- PHP

How to get array value without key

1. Use reset() to get the first value.

Example:

<?php

$colors = [
    'shoes' => 'blue',
    'hat' => 'black',
    'jacket' => 'brown',
];

echo reset($colors);

?>

Output: blue

2. Use end() to get the last value.

<?php

$colors = [
    'shoes' => 'blue',
    'hat' => 'black',
    'jacket' => 'brown',
];

echo end($colors);

?>

Output: brown

3. Use foreach() loop to get all the array values with their keys.

<?php

$colors = [
    'shoes' => 'blue',
    'hat' => 'black',
    'jacket' => 'brown',
];

foreach($colors as $key => $value) {
    echo $key . ' - ' . $value . '<br>';
}

?>

Output:

shoes – blue
hat – black
jacket – brown