Array
Array
PHP Arrays
<?php
$stuff = array("Hi", "There");
echo $stuff[1], "\n";
?>
There
Key / Value
<?php
$stuff = array("name" => "Chuck",
"course" => "PHPIntro");
echo $stuff["course"], "\n";
?>
PHPIntro
Dumping an Array
Array(
[name] => Chuck
[course] => PHPIntro
)
Building up an Array
<?php
$stuff = array("name" => "Chuck",
"course" => "PHPIntro");
foreach($stuff as $k => $v )
{ echo "Key=",$k," Val=",
$v,"\n";
}
?>
Key=name Val=Chuck
Key=course Val=PHPIntro
Arrays of Arrays
$products =
The elements of an array( 'paper'
array can be many => array(
things other than a 'copier' => "Copier & Multipurpose",
'inkjet' => "Inkjet Printer",
string or integer. You 'laser' => "Laser Printer",
can even have 'photo' => "Photographic Paper"),
objects or other 'pens' => array(
'ball' => "Ball Point",
arrays. 'hilite' =>
"Highlighters", 'marker'
=> "Markers"),
'misc' => array(
'tape' => "Sticky
Tape", 'glue' =>
"Adhesives", 'clips' =>
"Paperclips")
echo $products["pens"]["marker"];
);
Markers
Array Functions
Array(
[name] => Chuck
[topic] => PHP
[course] => PHPIntro
)
Arrays and Strings
=
>
PHP Global Variables