php?数组

WBOY
Release: 2016-06-20 12:54:00
Original
865 people have browsed it

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


回复讨论(解决方案)

$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);
Copy after login
Array(    [3] => 张三    [7] => 李四    [9] => 王五    [2] => 赵六)
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template