list函數語法結構

<?php
	/*
	list()函數做用,將數組中的元素轉爲變量使用
	1.等號左邊使用list()函數,等號右邊只能是一個數組
	2.數組中有幾個元素,在list()中就用幾個參數,並且參數必須是變量(
		新聲明的自定義變量),不能是值
	3.只能將索引數組(下標是連續),轉爲變量,是按下標0開始找的
	4.能夠在list()參數中經過,空項選擇性的接收數組中的元素
	*/

	list($id,$name,$age) = array(1,"zhangsan",23);

	echo $id."<br/>";
	echo $name."<br/>";
	echo $age."<br/>";

	/*
	1
	zhangsan
	23
	*/
	echo "<hr/>";

	$str="lisi,23,shanghai";
	list($name,$age,$addr) =explode(",",$str);

	echo $name."<br/>";
	echo $age."<br/>";
	echo $addr."<br/>";
	/*
	lisi
	23
	shanghai
	*/
?>
相關文章
相關標籤/搜索