Hello! There is a problem for which you need a solution. I have a multidimensional array:

["order_1"]=> array(3) { ["name"]=> string(6) "lkmndf" ["desc"]=> string(10) "lnkdlfnslk" ["files"]=> array(2) { [0]=> string(13) "sort-logo.png" [1]=> string(60) "Lalaala.jpg" } } ["order_2"]=> array(3) { ["name"]=> string(19) "lkmnsldnkmflknsldkn" ["desc"]=> string(15) "lkndslfknlskdmn" ["files"]=> array(2) { [0]=> string(12) "IMG_0.JPG" [1]=> string(63) "sort.jpg" } } } 

It has the key "files" which at the beginning should be combined into a line through "," in "order_1", then in "order_2" and then combined into one separated by a space. And the biggest snag is that these “orders” can be created indefinitely.

    1 answer 1

    If I understand everything correctly, then something like this (i is your order_1, order_2 ...):

     $arr = [ "order_1"=>[ "name"=>"lkmndf", "desc"=> "lnkdlfnslk", "files"=> ["sort-logo.png","Lalaala.jpg"] ], "order_2" =>[ "name"=>"lkmnsldnkmflknsldkn", "desc"=>"lkndslfknlskdmn", "files"=> ["IMG_0.JPG", "sort.jpg"] ] ]; $result = ""; foreach($arr as $key => $value ) { $result .= implode(',',$value['files']). " "; } var_dump($result); 
    • the code is not quite right, because when the code is executed, the result will be doubled when the code is first executed 2 times, the first part of the array will be displayed, then 2 times the second part and in the middle the right answer will turn out - Aleksei .C
    • "sort-logo.png, Lalaala.jpg IMG_0.JPG, sort.jpg need such a key? Or Lalaala.jpg IMG_0.JPG? - Kostiantyn Okhotnyk
    • It should turn out like this: sort-logo.png, Lalaala.jpg IMG_0.JPG, sort.jpg - Aleksei .C
    • I replaced the working code. Look, it returns to me. - Kostiantyn Okhotnyk
    • Yes, everything is right. Thank you! - Aleksei .C