Home > Backend Development > PHP Tutorial > 求解一路题

求解一路题

WBOY
Release: 2016-06-13 12:50:19
Original
782 people have browsed it

求解一道题
$arr=array(
   array('id'=>1,'title'=>'分类1'),
   array('id'=>3,'title'=>'分类3'),
   array('id'=>2,'title'=>'分类2'),
   array('id'=>8,'title'=>'分类8'),
   array('id'=>111,'title'=>'分类111'),

);

如何换成下述代码?求解?
$arr=array(
   1=>array('id'=>1,'title'=>'分类1'),
   3=>array('id'=>3,'title'=>'分类3'),
   2=>array('id'=>2,'title'=>'分类2'),
   8=>array('id'=>8,'title'=>'分类8'),
   111=>array('id'=>111,'title'=>'分类111'),

);


------解决方案--------------------
foreach($arr as $v){<br />
     $ar[$v['id']]=$v;<br />
}<br />
print_r($ar);
Copy after login

------解决方案--------------------
直接上代码:
$arr=array(<br />
   array('id'=>1,'title'=>'分类1'),<br />
   array('id'=>3,'title'=>'分类3'),<br />
   array('id'=>2,'title'=>'分类2'),<br />
   array('id'=>8,'title'=>'分类8'),<br />
   array('id'=>111,'title'=>'分类111'),<br />
<br />
);<br />
list($a[1],$a[3],$a[2],$a[8],$a[111])=$arr;<br />
asort($a);<br />
var_dump($a);<br />
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