Hi
What does this mean
foreach ($beatles as $key => $beatle)
{
echo "<b>$key:</b> $beatle<br>";
}
$beatles is array
Thanks
Moderators: macek, egami, gesf
<?php
$example_array1 = array('Apple','Potato','Dog');
print_r($example_array1);
// Using print_r will show you the array items with a numeric index
Array
(
[0] => Apple
[1] => Potato
[2] => Dog
)
$example_array2 = array('fruit' => 'Apple', 'vegetable' => 'Potato', 'animal' => 'Dog');
print_r($example_array2);
// Using print_r will show you the array items with a named index
Array
(
[fruit] => Apple
[vegetable] => Potato
[animal] => Dog
)
?>
foreach ($beatles as $key => $value) // For each element in the $beatles array, extract the $key and $value
{
echo "<b>$key:</b> $value<br>"; // echo the $key (numeric or named) and that key's value
}

Return to PHP coding => General
Users browsing this forum: Google [Bot] and 3 guests