关于二维数组。

WBOY
Lepaskan: 2016-06-23 13:50:38
asal
837 orang telah melayarinya

<?php	$group1 = array(            ("name"=>"zs","age"=>"10","sex"=>"nan"),            ("name"=>"zs","age"=>"10","sex"=>"nan"),            ("name"=>"zs","age"=>"10","sex"=>"nan"),            ("name"=>"ls","age"=>"11","sex"=>"nan"),            ("name"=>"ww","age"=>"12","sex"=>"nv"),            ("name"=>"ls","age"=>"11","sex"=>"nan"),            ("name"=>"ww","age"=>"12","sex"=>"nv"),            ("name"=>"ls","age"=>"11","sex"=>"nan"),            ("name"=>"ww","age"=>"12","sex"=>"nv")	);	echo '<table border="1" width="800" align>';	echo '<caption><h1>数组转化为表格</h1><caption>';	foreach( $group as $row ){		echo '<tr>';		foreach( $row as $col ){			echo '<td>{$col}</td>';		}		echo '</tr>';	}	echo '</table>';?>
Salin selepas log masuk


这样写为何不对?


回复讨论(解决方案)

这个错在第三行

	$group = array(            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv")	);	echo '<table border="1" width="800" align>';	echo '<caption><h1>数组转化为表格</h1><caption>';	foreach( $group as $row ){		echo '<tr>';		foreach( $row as $col ){			echo "<td>{$col}</td>";		}		echo '</tr>';	}	echo '</table>';
Salin selepas log masuk
Salin selepas log masuk

	$group = array(            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"zs","age"=>"10","sex"=>"nan"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv"),            array("name"=>"ls","age"=>"11","sex"=>"nan"),            array("name"=>"ww","age"=>"12","sex"=>"nv")	);	echo '<table border="1" width="800" align>';	echo '<caption><h1>数组转化为表格</h1><caption>';	foreach( $group as $row ){		echo '<tr>';		foreach( $row as $col ){			echo "<td>{$col}</td>";		}		echo '</tr>';	}	echo '</table>';
Salin selepas log masuk
Salin selepas log masuk


array 一定要加么?

是的,不然怎么叫数组

如果你是在 php5.4 及以上,也可简写为:[ ]

是的,不然怎么叫数组

如果你是在 php5.4 及以上,也可简写为:[ ]


哦,感谢版主。还是用5.3的吧。太先进也不好。
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan