Transform array
I'd like to transform input array from:
array(1) {
["option"]=>
array(2) {
[0]=>
string(8) "fdfsafsd"
[1]=>
string(7) "dasdasd"
...
}
}
to
array(array('op开发者_开发技巧tion' => "fdfsafsd"), array('option' => "dasdasd"),...)
The key "option" can be whatever...
What would be the best practice?
Thanks!
Best practice would be to leave your array as it is. If you want to "transform" it, you need to assign new keys for values found in the "options" key.
$new_array = $old_array['options'];
That would get what you specified in your question, however I don't see why you'd do that in the first place.
you want to have an associative array with all the value on one key ??? That seems impossible because an associative array is one key => one Value.
so you probably want an array list, you can obtain it easely by:
$myArray = $originalArray['option'] which will be like that: array("fdfsafsd", "dasdasd",...)
精彩评论