Created
March 27, 2014 14:47
-
-
Save alancoleman/9809169 to your computer and use it in GitHub Desktop.
Array reminders - I've always found arrays and the various ways of accessing their contents more complicated than it actually is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Accessing array elements with square bracket syntax ¶ | |
Array elements can be accessed using the array[key] syntax. | |
*/ | |
$array = array( | |
"foo" => "bar", | |
42 => 24, | |
"multi" => array( | |
"dimensional" => array( | |
"array" => "foo" | |
) | |
) | |
); | |
var_dump($array["foo"]); | |
var_dump($array[42]); | |
var_dump($array["multi"]["dimensional"]["array"]); | |
/* | |
example from: php.net/manual/en/language.types.array.php | |
The above example will output: | |
string(3) "bar" | |
int(24) | |
string(3) "foo" | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment