[英]Convert associative array to key=>value
I have the following array 我有以下数组
Array
(
[0] => Array
(
[id] => 5
[name] => 44
)
[1] => Array
(
[id] => 9
[name] => 55
)
)
i need to convert it to 我需要将其转换为
array( '5' => '44', '9' => '55' )
i tried all function of arrays from php.net but i could not figure out how to do it 我尝试了来自php.net的数组的所有功能,但我不知道该怎么做
did you try foreach
? 你尝试过
foreach
吗?
$result = array();
foreach($yourarray as $entry) {
$result[$entry['id']] = $entry['name'];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.