Implode multidimensional array with different glue in php -


i have array below:

array (     [22] => array         (             [0] => 60             [29] => array                 (                     [0] => 6                 )              [30] => array                 (                     [0] => 5                     [1] => 8                 )              [31] => array                 (                     [0] => 7                     [1] => 9                     [2] => 14                     [3] => 26                 )          )      [23] => 12     [35] =>10     [42] =>22 ) 

now want implode array like

60[6][5||8][7||9||14||26]|12|10|22 

i have tried below code:

$arr = array_map(function($el){ return $el['tag_id']; }, $arr); $str = implode(',', $arr); 

but not implode required glue

how can it?

you can use code

 <?php $a= array(     22 => array(             0 => 60,             29 => array(                     0 => 6                 ),              30 => array                 (                     0 => 5,                     1 => 8                 ),              31 => array                 (                     0 => 7,                     1 => 9,                     2 => 14,                     3 => 26                 ),          ),      23 => 12,     35 =>10,     42 =>22, ); $string=''; foreach($a $arr){     if(is_array($arr)){         foreach($arr $array){             if(is_array($array)){                 $string .= '['.implode("||",$array).']';             }else{                 if($string!==''){ $string .= '|';}                 $string .= $array;             }         }     }else{         if($string!==''){ $string .= '|';}         $string .= $arr;     }  } echo $string;die;  ?> 

out put wil be

60[6][5||8][7||9||14||26]|12|10|22


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -