How can I add "Please choose" to the beginning of this array
$enDuration = range( 0 , 60);
Best would be it all happens in ONE line as it is for a language config file and should stay as clean as possible. Array_combine didn't work for me.
You can use array_merge
, like this:
$enDuration = array_merge(['Please choose'], range(0, 60));
$enDuration = array_merge(array('Please choose'),range( 0 , 60));
Works!
Use
$enDuration = range( 0 , 60);
$enDuration = array('Please choose') + $enDuration;
or
$enDuration = array('Please choose') + range( 0 , 60);
you can use array function like this
$enDuration = array('Please choose',range( 0 , 60));
print_r($enDuration);
also you can use array_merge
$a=array_merge(array('Please choose'),range( 0 , 60));
but there is some difference between array_merge
and array
, you can check difference in below output,
your desired output
You can always create a new array()
or merge with the array, but you can also just tell PHP to add it to the beginning of the array, and correct the keys automatically.
http://php.net/manual/en/function.array-unshift.php
$enDuration = range(0 , 60); array_unshift($enDuration, "Please choose");