my book has a strange example on page 27 (very beginning) and it doesn't explain how it works exactly
$person[0] = "Edison";
$person[1] = "Wankel";
$person[2] = "Crapper";
$creator['Light bulb'] = "Edison";
$creator['Rotary Engine'] = "Wankel";
$creator['Toilet'] = "Crapper";
$person = array('Edison', 'Wankel', 'Crapper');
$creator = array('Light bulb' => 'Edison',
'Rotary Engine' => 'Wankel',
'Toilet' => 'Crapper');
foreach ($person as $name) {
echo "Hello, $name\n";
}
foreach ($creator as $invention => $inventor) {
echo "$inventor created the $invention\n";
}
the output should be:
Hello, Edison
Hello, Wankel
Hello, Crapper
Edison created the Light bulb
Wankel created the Rotary Engine
Crapper created the Toilet
ok now how does that work exactly?
the $person[] thing was an array of people and i understand that. $creator[] is an array with the invention as the name of that one in the array and the assigned value to that part of the array is the creator and i understand that. assigning $person to being an array with the value of 3 people makes sense to me as well.
the $creator part, i do not understand. what do those => things mean?
on that first foreach line, does the part of ($person as $name) mean that it just created an array called $name which is exactly the same as the $person array?
if i knew what that => thing meant, i would probably be able to figure out the rest but i don't.