Thursday, 25 September 2014

list in PHP

PHP list() function is utilized to allocate values to a list of variables as though they were an array.
The variables in PHP list() will be allocated to elements of the array in the request they were basically stored in the array.

Syntax:

list(var1,var2,...)
var : Required. The first variable to assign a value to
var : Optional. More variables to assign values to
Note : This function only works on numerical arrays.

Example:

<?php
$names = array( "Sam","Peter","Jack" );
list($s, $p, $j) = $names;
echo "I am $s, he is $p and he is $j.";
?>

O/P:

I am Sam, he is Peter and he is Jack.

0 comments:

Post a Comment