PHP Array Function : array()

The php array() function is used to create array. It allows you to create indexed, associative and multidimensional arrays. The syntax for array() is as follows :

For Indexed array :
 $array_name = array(value1, value2, value3, ...., valueN);
For associative array :
 $array_name = array(key1 => value1, key2 => value2, key2 => value3, ...., keyN => valueN);
Example :
<?php
  $WebDev = array("HTML", "CSS", "JavaScript", "PHP", "MySql");
  $length = count($WebDev);

  for($x = 0; $x < $length; $x++) {
    echo $WebDev[$x] . "<br/>";
  }
?>
Output :

HTML
CSS
JavaScript
PHP
MySql


Next Topic :