php?数组
程序员文章站
2022-05-17 08:22:26
...
foreach($rows as $k => $v){ print_r($v); echo "
"; }输出的结果Array ( [id] => 3 [title] => 张三)Array ( [id] => 7 [title] => 李四 ) Array ( [id] => 9 [title] => 王五 )Array ( [id] => 2 [title] => 赵六 ) ......现在,要把输出的这些数组拼成一个新数组Array([3]=>张三 [7]=>李四 [9]=>王五 [2]=>赵六)
回复讨论(解决方案)
$ar = array( array('id' => 3, 'title' => '张三'), array('id' => 7, 'title' => '李四'), array('id' => 9, 'title' => '王五'), array('id' => 2, 'title' => '赵六'),);foreach($ar as $v) $res[$v['id']] = $v['title'];print_r($res);
Array( [3] => 张三 [7] => 李四 [9] => 王五 [2] => 赵六)