In PHP, you can display the values of an array using several methods, depending on the context. Below are some of the most common ways to display array values:
implode
<?php
$cars = array('1. Volkswagen', '2. Toyota', '3. Mercedes', '4. Ford', '5. BMW');
echo implode(', <br />', $cars);
?>
foreach Loop
<?php
$array = ['1. Volkswagen', '2. Toyota', '3. Mercedes', '4. Ford', '5. BMW'];
foreach ($array as $value) {
echo $value . "<br>";
}
?>
$array = [
"First Name" => "Jane",
"Last Name" => "Doe",
"Age" => 45,
"City" => "Amsterdam"
];
foreach ($array as $key => $value) {
echo $key . ": " . $value . "<br>";
}