php?数组

WBOY
WBOYOriginal
2016-06-20 12:54:00867browse

 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] => 赵六)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn