array list function - assign a list of variables in one operation

array list function - assign a list of variables in one operation

array-list-function-example-in-php.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>array list function - assign a list of variables in one operation</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="array list function - assign a list of variables in one operation">
  <meta name="keywords" content="php, example, code, array, function, list">
  <meta name="description" content="array list function - assign a list of variables in one operation">
  <style>
   h2, h3, h4{background:#eee; color:#000067;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h3{ padding:2px; margin:2px; font-size:18px;}
   h4{ padding:2px; margin:2px; font-size:14px;}
   body{ background:#FFFFFc;}
  </style>
 </head>
 <body>
  <h2>array list function - assign a list of variables in one operation</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------
     les make an array and fill up with some keys and values
     -----------------------------------------------------------
    */
    $myArray = array("apple","zoo","book");
    echo "<h4>Output of myArray</h4>";
    print_r($myArray);
    /*
     -------------------------------------------------------------------------------------
     we want to assign each value of the array to some variables in a single operation
     by using array list function
     -------------------------------------------------------------------------------------
    */
    list($fruit, $animal, $shelf) = $myArray;
    echo "<h4>Output of variables using array list function</h4>";
    print "$"."fruit = {$fruit}<br>";
    print "$"."animal = {$animal}<br>";
    print "$"."shelf = {$shelf}<br>";
   ?>
  </pre>
 </body>
</html>

array list function - assign a list of variables in one operation - output in the browser

No comments:

Post a Comment

leave your comments here..