there is such a cycle

$tabs[] = array('name'=>$Rusname, 'sub'=>$Razdel, 'cc'=>$Komponent, 'code'=>$Engname); function by_code($tabs) { $result = array(); foreach ($tabs as $v) { $result[$v['code']][] = $v['cc']; } return $result; } 

I get such an array

 Array ( [about] => Array ( [0] => 479 [1] => 967 ) [doc] => Array ( [0] => 480 ) [dop] => Array ( [0] => 481 ) [faq] => Array ( [0] => 482 ) [off] => Array ( [0] => 483 ) ) 

[about], [doc], [dop], [faq], [off] - dynamic data, i.e. maybe [dsdfg] [124sdr], etc.

How do I get this thing out, what would happen

 <div>479 967</div> <div>480</div> <div>481</div> <div>482</div> <div>483</div> 

    1 answer 1

     foreach ($result as $key => $value) { $div = '<div>'; foreach($result[$key] as $v) { echo $v . ' '; } $div .= '</div>'; echo $div; } 

    Where $result is your multidimensional array.

    • 3
      echo "<div>".implode(' ', $result[$key])."</div>" not it easier? and without an extra space at the end - teran
    • @teran or so - mix
    • it turns out 1 cycle we get data, 2 cycle we display data? - Sincopa
    • function by_code ($ tabs) {$ result = array (); foreach ($ tabs as $ v) {$ result [$ v ['code']] [] = $ v ['cc']; } foreach ($ result as $ key => $ value) {echo "<div>". implode ('', $ result [$ key]). "</ div>"; } return $ result; } - Sincopa
    • @Sincopa Not really getting and displaying. A multidimensional array is simply iterated over in two cycles. - mix