php - Mutilple Array puzzel -
i have array :
$myarrays = array( array(1, 2, 3, 4), array(5, 6, 7, 8), array(9, 10, 11, 12), array(13, 14, 15, 16) );
i need print output :
1 5 9 13 14 10 6 2 3 7 11 15 16 12 8 4
you can try is
$myarrays = array( array(1, 2, 3, 4), array(5, 6, 7, 8), array(9, 10, 11, 12), array(13, 14, 15, 16) ); $i = 0; foreach($myarrays $key => $value){ $i = $key; foreach($value $keys =>$values){ $addarray[$i] = $values; $i = $i+4; } } ksort($addarray); $arrays = array_chunk($addarray,4); krsort($arrays[1]); krsort($arrays[3]); $final = array_merge($arrays[0],$arrays[1],$arrays[2],$arrays[3]); foreach ( $final $key => $value){ echo $value ."<br>"; }
Comments
Post a Comment