数组用下标回重组数组,为什么重组出来的数组下标一直是第一个

WBOY
Release: 2016-06-13 11:47:04
Original
1310 people have browsed it

数组用下标来重组数组,为什么重组出来的数组下标一直是第一个?

<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 />
Copy after login


var_dump() 出来的,下标一直都是[8]这个。。。哪里写错了?
------解决方案--------------------
在循环外面打印
------解决方案--------------------
$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 />";
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!