Heim >Backend-Entwicklung >PHP-Tutorial >php?数组
foreach($rows as $k => $v){ print_r($v); echo "<br>"; }输出的结果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] => 赵六)