Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Simple Syntax question

Featured Replies

I can't seem to get this right:

array(
		'label'	=> 'Select Home Score',
		'desc'	=> 'Select home score',
		'id'	=> $prefix.'homescore-select',
		'type'	=> 'select',
		'options' => array(foreach (range(0, 20) as $number) {
    array($number);
    	})
	)

I'm trying to put an incremental select list within an array.

Hey Mantis,

 

not 100% sure what you're trying to achieve, but by looking at your code I think this is what you are looking for:

 

<?php

$prefix = "";

$someArray = array(
		'label'	=> 'Select Home Score',
		'desc'	=> 'Select home score',
		'id'	=> $prefix . 'homescore-select',
		'type'	=> 'select',
		'options' => call_user_func(function(){

			$optionsArray = array();

			for($i = 0; $i <= 20; $i++){
			
				$optionsArray[] = array($i);
			}

			return $optionsArray;
		})
);


?>

This script simply sets "options" to an array, which contains 20 other arrays containing a number from 0 to 20.

 

You also need a PHP version of 5.3 or higher I believe.

 

Léon

  • Author

Thanks Leon, I was actually trying to do this but more succinctly:

 

array(
		'label'	=> 'Select Home Score',
		'desc'	=> 'Select home score',
		'id'	=> $prefix . 'homescore-select',
		'type'	=> 'select',
		'options' => array (
			'zero' => array (
				'label' => '0',
				'value'	=> '0'
			),
			'one' => array (
				'label' => '1',
				'value'	=> '1'
			),
			'two' => array (
				'label' => '2',
				'value'	=> '2'
			),
			'three' => array (
				'label' => '3',
				'value'	=> '3'
			),
			'four' => array (
				'label' => '4',
				'value'	=> '5'
			),
			'five' => array (
				'label' => '6',
				'value'	=> '6'
			)
		)
	)

Otherwise I'll just write it out.

I hope that this does what you want:

<?php

$prefix = "";

$numberArray = ["zero", "one", "two", "three", "four", "five", "six", "seven"];

$someArray = array(
		'label'	=> 'Select Home Score',
		'desc'	=> 'Select home score',
		'id'	=> $prefix . 'homescore-select',
		'type'	=> 'select',
		'options' => call_user_func(function(){

			global $numberArray;

			$optionsArray = array();

			// Loop through $numberArray.
			for($i = 0; $i < count($numberArray); $i++){
			
				$optionsArray[$numberArray[$i]] = array(
					"label" => $i,
					"value" => $i
				);
			}

			return $optionsArray;
		})
);


?> 

 

If you want more options you can just extend $numberArray.

 

Léon

Edited by Leonvv

Léon,

I hoping to get your help with another topic?

www(dot)webdesignerforum(dot)co(dot)uk/topic/62025-please-help-my-to-add-a-calculator-to-my-website-pretty-please/

Thanks in advance!

Edited by jimmymustang

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.