Table of contents Home page
$x = array(); // Creates an empty array echo 'The array $x contains ' . count($x) . " elements.\n";
$x = array('a', 'b', 'c'); // Creates an indexed array with 3 elements containing a letter foreach($x as $k => $v) // Print the values with their indices { echo "$k => '$v'\n"; } $x = array(1 => 'a', -3 => 'b', 5 => 'c'); // Creates a similar array but with non-consecutive indices foreach($x as $k => $v) // Print the values with their indices { echo "$k => '$v'\n"; } $x = array('unu' => 'one', 'du' => 'two', 'tri' => 'three'); // Creates an associative array foreach($x as $k => $v) // Print the values with their indices { echo "'$k' => '$v'\n"; }