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.
精彩评论