2

我有以下数组

Array
(
    [0] => Array
        (
            [id] => 5
            [name] => 44
        )

    [1] => Array
        (
            [id] => 9
            [name] => 55
        )

)

我需要将其转换为

array( '5' => '44', '9' => '55' ) 

我尝试了来自 php.net 的所有数组功能,但我不知道该怎么做

4

1 回答 1

5

你试过了foreach吗?

$result = array();
foreach($yourarray as $entry) {
  $result[$entry['id']] = $entry['name'];
}
于 2013-09-04T03:15:48.370 回答