'I'm trying to understand php foreach list, I'm missing something [duplicate]

This should probably be simple, but I'm missing something.

I want to have two arrays, combine them, then list out the values.

I obviously don't understand arrays, or array_combine, or the foreach list... but I'm not sure which or where I'm going awry.

Here's the code:

    <?php

       $media_ids = array('64767','64764');
       $alt_text = array('test 1','test 2');
       
       $img_meta = array_combine($media_ids, $alt_text);
                         
    foreach ($img_meta as list($id, $alt) ) {

        echo $id.' > '.$alt.'<br /><br />';

   }

The results I am looking to end up with would be:

64767 > test 1

64764 > test 2

Any help in accomplishing this would be very appreciated!

Chris



Solution 1:[1]

This is how it's done:

foreach ($img_meta as $id => $alt) {

    echo $id.' > '.$alt.'<br /><br />';

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aranxo