Array can have any size and contain any sort of value. No threat of going past exhibit limits. PHP arrays are associative arrays which permit component to be put away in connection to a key value instead of a strict straight record arrange.
$capitals["name"] = "John";
$capitals["AR"] = "Little Rock";
Initialize an array:
$colors = array("red", "green", "blue");
print("The 2nd color is $colors[1]."); // prints green
$capitals = array("name" => "John", "AR" => "Little Rock");
print("$capitals[name]"); // prints John, no quotes around key inside ""
E. Print contents of an array for debugging:
print_r($colors);
Produces:
Array
(
[0] => red
[1] => green
[2] => blue
)
print_r($capitals);
produces:
Array
(
[name] => John
[AR] => Little Rock
)
Pull values out of an array:
$colors = array("red", "green", "blue");
list($c1, $c2) = $colors;
print("$c1 and $c2"); // prints "red and green"
Delete from an array:
unset($colors[1]); // $colors now contains red and blue at indexes 0 and 2.
Summary of all array functions in the PHP core: http://www.php.net/manual/en/ref.array.php
$capitals["name"] = "John";
$capitals["AR"] = "Little Rock";
Initialize an array:
$colors = array("red", "green", "blue");
print("The 2nd color is $colors[1]."); // prints green
$capitals = array("name" => "John", "AR" => "Little Rock");
print("$capitals[name]"); // prints John, no quotes around key inside ""
E. Print contents of an array for debugging:
print_r($colors);
Produces:
Array
(
[0] => red
[1] => green
[2] => blue
)
print_r($capitals);
produces:
Array
(
[name] => John
[AR] => Little Rock
)
Pull values out of an array:
$colors = array("red", "green", "blue");
list($c1, $c2) = $colors;
print("$c1 and $c2"); // prints "red and green"
Delete from an array:
unset($colors[1]); // $colors now contains red and blue at indexes 0 and 2.
Summary of all array functions in the PHP core: http://www.php.net/manual/en/ref.array.php
No comments:
Post a Comment