Advertisement
Shailrshah

Indexed and associative Arrays in PHP

Apr 28th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <body>
  4.         <?php
  5.             $numbers = array(4, 2, 5, 3); //Indexed array
  6.             echo "The first element is " . $numbers[0];
  7.             echo "<br>The number of elements are " . count($numbers);
  8.             rsort($numbers);
  9.             echo "<br>The elements have been sorted in reverse.";
  10.             print_r($numbers);
  11.  
  12.             $myName = array(); //Associative array
  13.             $myName["first"] = "Shail";
  14.             $myName["middle"] = "R.";
  15.             $myName["last"] = "Shah";
  16.             echo "<br>My last name is " . $myName["last"];
  17.  
  18.             $myColleges = array("JC" => "Pace", "Engg" => "TSEC");
  19.             echo "<br>I wasted 2 years at " . $myColleges["JC"];
  20.         ?>
  21.     </body>
  22. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement