using a list data structure in php

Sometimes it is handy to use “list” in php. Here is the code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>

<body>
<?php
function small_numbers()
{
  $myarray = array(0,1,2);
  return $myarray;
//	return array(0,1,2);
}

list($num1, $num2, $num3) = small_numbers();

echo $num1 . " " . $num2 . " " . $num3 . "<br>";

list($a, $b, $c) = array("one", "two", "three");

echo $a . " " . $b . " " . $c . "<br>";
?>
</body>
</html>

 

Add a Comment

Your email address will not be published. Required fields are marked *