convert 2d array to a string using php

前端 未结 5 1360
攒了一身酷
攒了一身酷 2021-01-22 06:39

I have the following array

 01 03 02 15
 05 04 06 10
 07 09 08 11
 12 14 13 16

I want to convert a string like the following:

         


        
5条回答
  •  孤街浪徒
    2021-01-22 07:24

    Given your array as $myArray, like this:

    $newArray = array();
    foreach ($myArray as $row) {
        $rowValue = implode(',', $row);
        $newArray[] = $rowValue;
    }
    $finalString = implode('|', $newArray);
    

提交回复
热议问题