Home > Backend Development > PHP Tutorial > 再问一个PHP数组格式有关问题,

再问一个PHP数组格式有关问题,

WBOY
Release: 2016-06-13 12:26:45
Original
765 people have browsed it

再问一个PHP数组格式问题,请教大家。
先感谢上一个数组的问题xuzuning帮我解答了,我想再问一个,如果我把表里type的值放到数组里面这个也可以做到吗?





通过上面这个表实现以下数组

<br /><br />Array(  <br /><br />[classname] => array(<br />            [0]=><br />            [1]=>婚庆服务<br />            [2]=>机械设备<br />            [3]=>医院医疗<br />            [4]=>照明灯饰<br />            [5]=>教育培训<br />            [6]=>化工涂料<br />            [7]=>美容健身<br />            [8]=>餐饮美食<br />            [9]=>汽车服务<br />            )<br />[layout] => array(<br />            [0]=><br />            [1]=>常规<br />            [2]=>两列<br />            [3]=>三列<br />            [4]=>网格<br />            )<br />)<br /><br />
Copy after login

------解决思路----------------------
按我那个写法,$res 本就是你现在要的格式
由于你那个帖子要的是下标数组,所以才会有
$res = array_values($res);
------解决思路----------------------
while($row = mysql_fetch_assoc($rs)) {
  if($row['typeid'] == 0) $row['typevalue'] = ''; 
  $res[$row['type']][] = $row['typevalue'];
}

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