开发者

implode multidimensional array

while($row=mysql_fetch_assoc($query)) {   
   $id = $row['id'];
   $col1 = $row['name1'];
   $col2= $row['name2'];
   $col3= $row['name3']; 

   ${"$id"} = array("$col1","开发者_开发百科$col2","$col3");
   ${"$s".$i}[] = ${"$id"};
 }

This is just a breif example of what i'm trying to accomplish, $i is incremented somewhere else. I'm trying to implode the arrays in the array. So below I have imploded the main array but how do I implode the other arrays?

for($i=0;$i<11;$i++) {
  $array = ${"s" . $i};
  $outcomes = implode("",$array); //implodes main array
}


Not quite sure what you are trying to achieve here, but does this help?

function recursive_echo ($arr, $spacing = 0) {
  $padding = ($spacing) ? str_pad('', $spacing) : '';
  foreach ($arr as $key => $val) {
    if (is_array($val)) {
      echo "{$padding}{$key}:<br />\n";
      recursive_echo($val, $spacing + 2);
    } else {
      echo "{$padding}{$val}<br />\n";
    }
  }
}

This function just echoes out the data, but it illustrates how to recurse through a multi-dimensional array where the number of dimensions is unknown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜