I want to reference the value of an array from the same array only at a different level. Is that even possible, because after i declaring the array, i can refer to that element properly, but can i do that inside of an array? Thanks!
$literature = [
'authors'=>[
['name' => 'hhh', 'adress' => '[email protected]','yearOfBirth' => '1869'],
['name' => 'yyy', 'adress' => 'saintexupé[email protected]','yearOfBirth' => '1900'],
['name' => 'zzz', 'adress' => '[email protected]','yearOfBirth' => '1859']
],
'books'=>[
['title' => 'ggg', 'author' => $literature ['authors'][0]['name'], 'year' => 1943],
['title' => 'uuu', 'author' => $literature ['authors'][0]['name'], 'year' => 1887],
['title' => 'ttt!', 'author' => $literature ['authors'][0]['name'], 'year' => 1929],
['title' => 'vvv', 'author' => $literature ['authors'][0]['name'], 'year' => 1936],
['title' => 'ooo', 'author' => $literature ['authors'][0]['name'], 'year' => 1938]
]
];
echo $literature ['authors'][0]['name'];// thats a proper reference, that results in showing the value, but when i print the whole array, that value displays as zero
foreach ($literature as $innerKeylevel1 => $innerDatalevel1) {
foreach ($innerDatalevel1 as $innerKeylevel2 => $innerDatalevel2) {
foreach ($innerDatalevel2 as $dataKey => $data) {
echo $data . " - ";
}
echo "</br>";
}
}
$litteraturearray in two rounds; one for authors, and one for books. Then you can use the first, already declared part, in the second declaration.