chapter-9
chapter-9
SUPERGLOBALS
Chapter 9
3 $_SERVER
Array 4
5
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Section 1 of 5
ARRAYS
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Arrays
Background
$month = array(
array("Mon","Tue","Wed","Thu","Fri"),
array("Mon","Tue","Wed","Thu","Fri"),
array("Mon","Tue","Wed","Thu","Fri"),
array("Mon","Tue","Wed","Thu","Fri")
);
echo $month[0][3]; // outputs Thu
$cart = array();
$cart[] = array("id" => 37, "title" => "Burial at Ornans", "quantity" => 1);
$cart[] = array("id" => 345, "title" => "The Death of Marat", "quantity" => 1);
$cart[] = array("id" => 63, "title" => "Starry Night", "quantity" => 1);
$days[ ] = "Sun";
Array ([0] => Mon [1] => Tue [2] => Wed [3] => Thu [4] => Fri [7] => Sat)’
You can explicitly delete array elements using the unset() function
You can explicitly delete array elements using the unset() function.
array_values() reindexes the array numerically
Since array keys need not be sequential, and need not be integers,
you may run into a scenario where you want to check if a value has
been set for a particular key.
To check if a value exists for a key, you can therefore use the isset()
function, which returns true if a value has been set, and false otherwise
There are many built-in sort functions, which sort by key or by value.
To sort the $days array by its values you would simply use:
sort($days);
As the values are all strings, the resulting array would be:
Array ([0] => Fri [1] => Mon [2] => Sat [3] => Sun [4] => Thu [5] => Tue [6] => Wed)
• array_keys($someArray)
• array_values($someArray)
• array_rand($someArray, $num=1)
• array_reverse($someArray)
• array_walk($someArray, $callback, optionalParam)
• in_array($needle, $haystack)
• shuffle($someArray)
• …
3 $_SERVER
Array
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development