php - Foreach comes back as Array Array -
not sure i'm doing wrong one, when attempt foreach
loop variable, comes array array
.
php code:
<?php foreach ($thing $t) : ?> <?php $thisstuff = $t[stuff]; ?> <?php echo $thisstuff; ?> <?php endforeach; ?>
output: array array
could possibly there array within $thisstuff
? if loop through data?
if have multidimensional array you'll need use recursive function.
an example might this
function unfoldarray($array,$output = array()) { if(is_object($array)) { $array = (array)$array; } foreach($array $key => $value) { if(is_array($value) || is_object($value)) { //$output[] = $key; $output = unfoldarray($value,$output); } else { $output[] = $value; } } return $output; }
the above function, given array like
$array = array( "one", "two", "three" => array("a","b","c"), "four" => array("x","y","z"), "five", "six" => array( "sub_one", "sub_two", "sub_three" => array("sub_a","sub_b","sub_c") ), "seven" ); $output = unfoldarray($array);
would return flat array this
// $output [ "one", "two", "a", "b", "c", "x", "y", "z", "five", "sub_one", "sub_two", "sub_a", "sub_b", "sub_c", "seven" ]
you may notice values "three" , "six" omitted result array because key, if wan include them uncomment line //$output[] = $key; in function.
once have array may loop foreach. might not need, should give direction follow.
Comments
Post a Comment