An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.
I think that this can be helpfull for you, Pay attention to Example n° 6
https://www.php.net/manual/en/language.types.array.php
What you need is to access to a multidimensional array. In PHP you don't need the "dot notation" (album.title
or elem1.sub_elem2
) as you called ,to access to elements.
You can access to multidimensional array by the key of element, in this way:
$multiarray["element1"]["sub_element2"]["sub_sub_elementX"];
Having said that, I will leave an example here that explains better what I wanted to say.
Example Using Your Data:
<?php
$array = array( "Album Title 1" => array( "Track Title 1" => 27,
"Track Title 2" => 18,
"Track Title 3" => 7 ),
"Album Title 2" => array( "Track Title 1" => 41,
"Track Title 2" => 17,
"Track Title 3" => 12 )
);
echo($array["Album Title 1"]["Track Title 2"]);
//Output will be 18
echo("<br/><br/>");
foreach($array as $Album => $Track){
foreach($Track as $Title => $number){
echo("Album : ".$Album."<br/>");
echo("Track : ".$Title."<br/>");
echo("Number : ".$number."<br/>");
}
}
/* Output will be:
Album : Album Title 1
Track : Track Title 1
Number : 27
Album : Album Title 1
Track : Track Title 2
Number : 18
Album : Album Title 1
Track : Track Title 3
Number : 7
Album : Album Title 2
Track : Track Title 1
Number : 41
Album : Album Title 2
Track : Track Title 2
Number : 17
Album : Album Title 2
Track : Track Title 3
Number : 12
*/
?>
You can try the code on http://phptester.net/