Home > Article > Backend Development > 数组用下标回重组数组,为什么重组出来的数组下标一直是第一个
数组用下标来重组数组,为什么重组出来的数组下标一直是第一个?
<br /><?php<br />$id = array(8,31,32);<br /><br />$resarr = array();<br />foreach($id as $num)<br />{<br /> $product = array(<br /> array(<br /> 'pid'=>'10', <br /> 'name'=>'产品1'<br /> ),<br /> array(<br /> 'pid'=>'11', <br /> 'name'=>'产品2'<br /> )<br /> );<br /> foreach($product as $key => $value)<br /> {<br /> $result_value = "";<br /> foreach($value as $k => $v)<br /> {<br /> $result_value .= $result_value ? "|" : "";<br /> $result_value .= $v['pid'];<br /> }<br /> $product[$key]['value'] = $result_value;<br /> }<br /> $resarr[$num] = $product;<br /> var_dump($resarr);<br /> echo "<hr />";<br />}<br />
$id = array(8,31,32);<br /><br />$resarr = array();<br />foreach($id as $num)<br />{<br /> $product = array(<br /> array(<br /> 'pid'=>'10', <br /> 'name'=>'产品1'<br /> ),<br /> array(<br /> 'pid'=>'11', <br /> 'name'=>'产品2'<br /> )<br /> );<br /> foreach($product as $key => $value)<br /> {<br /> $result_value = "";<br /> foreach($value as $k => $v)<br /> {<br /> $result_value .= $result_value ? "<br><font color='#FF8000'>------解决方案--------------------</font><br>" : "";<br /> $result_value .= $v['pid'];<br /> }<br /> $product[$key]['value'] = $result_value;<br /> }<br /> $resarr[$num] = $product;<br /> <br />}<br />var_dump($resarr);<br />echo "<hr />";