Looping a multidimensional array in php

前端 未结 3 1460
醉酒成梦
醉酒成梦 2020-11-27 23:09

I have a multidimensional array like this:

array(2) {
  [1]=>
  array(3) {
    [\"eventID\"]=>
    string(1) \"1\"
    [\"eventTitle\"]=>
    string         


        
3条回答
  •  庸人自扰
    2020-11-27 23:41

    You're best using the foreach construct to loop over your array. The following is untested and is off the top of my head (and probably therefore not as thought through as it should be!) but should give you a good start:

    foreach ($mainArray as $event)
    {
      print $event["eventTitle"];
    
      foreach ($event["artists"] as $artist)
      {
         print $artist["name"];
         print $artist["description"];
    
         $links = array();
         foreach ($artist["links"] as $link)
         {
           $links[] = $link["URL"];
         }
         print implode(",", $links);
      }
    }
    

提交回复
热议问题