PHP Arrays: How to create an array in PHP

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


Arrays in PHP can be created usning array() declaration as follows:

$new_array = array();

This would create a new empty array. To create an array with initial values,

$new_array = array(1, 2);

$str_array = array("Jose", "Andy");

This creates 2 arrays $new_array and $str_array with element 1,2 and "Jose", "Andy" respectively.





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.