list construct and each

list construct and each

list
list is basically used to assign the array values into variables.

Follwing example shows how to use list construct
$arr = array(”fame”,”22″,”Male”);

list($name,$age,$sex) = $arr;

echo $name;
echo “<br>”;
echo $age;
echo “<br>”;
echo $sex;
echo “<br>”;

each
each will get a array as argument and return the key and value of that array. And also each is used with list to traverse an array.

Example

$arr1 = array(”1″=>”One”,”2″=>”Two”);
while(list($k,$v) = @each($arr1)){
echo “<br>”;
echo $k;
echo “<br>”;
echo $v;
}

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.