Skip to content

Instantly share code, notes, and snippets.

@drukaman
Last active October 26, 2015 22:12
Show Gist options
  • Select an option

  • Save drukaman/d52d0d0e03601ee256bb to your computer and use it in GitHub Desktop.

Select an option

Save drukaman/d52d0d0e03601ee256bb to your computer and use it in GitHub Desktop.
Recursive and multi-dimensional arrays
<?php
$fruits = array ( "fruits" => array ( "a" => "orange",
"b" => "banana",
"c" => "apple"
),
"numbers" => array ( 1,
2,
3,
4,
5,
6
),
"holes" => array ( "first",
5 => "second",
"third"
)
);
// Some examples to address values in the array above
echo $fruits["holes"][5]; // prints "second"
echo $fruits["fruits"]["a"]; // prints "orange"
unset($fruits["holes"][0]); // remove "first"
// Create a new multi-dimensional array
$juices["apple"]["green"] = "good";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment