-2

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

Chris
  • 315
  • 2
  • 7

1 Answers1

0

This is how it's done:

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

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

}
Aranxo
  • 422
  • 2
  • 10
  • Please close duplicate questions instead of answering them. [The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.](https://stackoverflow.com/help/duplicates#:~:text=The%20fundamental%20goal%20of%20closing%20duplicate%20questions%20is%20to%20help%20people%20find%20the%20right%20answer%20by%20getting%20all%20of%20those%20answers%20in%20one%20place.) – mickmackusa May 15 '22 at 08:16
  • @mickmackusa I see the point and support it. But I didn't even know that I have the rights to close a question. Neither how to do it. I just tried to edit a random question, just to see how to do it (and canceling the edit of course). But could not figure it out. Is there some tutorial how to edit a question? – Aranxo May 15 '22 at 23:18
  • If I recall correctly, you cannot vote to close a question until you have 3000 rep; you can however "flag" a post as a duplicate -- this is VERY helpful. As for editing other people's posts, you can "suggest an edit", then your edit will be reviewed before it is committed. Don't worry about "getting stuff wrong", just be well-intentioned and the community will help you along. The [help] pages are a great place to start reading. – mickmackusa May 15 '22 at 23:30
  • Ok, in the future, if I'm suspicious the current question is quite common so it should be answered already, I will search for similar content first and then flag it, if I find some. – Aranxo May 16 '22 at 00:27
  • That would instantly make you one of the most helpful contributors on all of Stack Overflow! Keep in mind that this approach does not prevent you from posting answers, it just means that you will need to move your focus to earlier asked questions and only add a new answer to older questions if you have something unique and valuable to add to the old page. – mickmackusa May 16 '22 at 00:40