变换数组
我想将输入数组从: 转换
array(1) {
["option"]=>
array(2) {
[0]=>
string(8) "fdfsafsd"
[1]=>
string(7) "dasdasd"
...
}
}
为
array(array('option' => "fdfsafsd"), array('option' => "dasdasd"),...)
关键“选项”可以是任何内容...
最佳实践是什么?
谢谢!
I'd like to transform input array from:
array(1) {
["option"]=>
array(2) {
[0]=>
string(8) "fdfsafsd"
[1]=>
string(7) "dasdasd"
...
}
}
to
array(array('option' => "fdfsafsd"), array('option' => "dasdasd"),...)
The key "option" can be whatever...
What would be the best practice?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最佳实践是保持阵列不变。如果要“转换”它,则需要为“options”键中找到的值分配新键。
这将得到您在问题中指定的内容,但是我不明白您为什么首先要这样做。
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.
That would get what you specified in your question, however I don't see why you'd do that in the first place.
你想要一个关联数组,其中一个键上的所有值???
这似乎是不可能的,因为关联数组是一个键 =>一个值。
所以你可能想要一个数组列表,你可以通过以下方式轻松获取它:
$myArray = $originalArray['option']
将会是这样的:
数组(“fdfsafsd”,“dasdasd”,...)
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",...)