Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Created March 27, 2014 14:47
Show Gist options
  • Save alancoleman/9809169 to your computer and use it in GitHub Desktop.
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.
<?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