您的$choices
数组只有数字键,因此array_unshift()
可以完全按照您的意愿行事。
$choices = array(
array('label' => 'test1','value' => 'test1'),
array('label' => 'test2','value' => 'test2'),
array('label' => 'test3','value' => 'test3'),
);
echo $choices[0]['label']; // echoes 'test1'
$array_to_add = array('label' => 'All','value' => 'all');
array_unshift($choices, $array_to_add);
/* resulting array would look like this:
$choices = array(
array('label' => 'All','value' => 'all')
array('label' => 'test1','value' => 'test1'),
array('label' => 'test2','value' => 'test2'),
array('label' => 'test3','value' => 'test3'),
);
*/
echo $choices[0]['label']; // echoes 'All'