May 28, 201313 yr 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.
May 28, 201313 yr 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
May 28, 201313 yr 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.
May 28, 201313 yr 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 May 28, 201313 yr by Leonvv
May 28, 201313 yr 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 May 28, 201313 yr by jimmymustang
Create an account or sign in to comment