How to read the specific set elements from an array - PHP -
i have array, trying store first element(15) in 1 array(xaxis) , second element(42) fifth(23) in array(yaxis) , again want store sixth element(15) in array - xaxis , later 4 elements in yaxis. have more hundred elements in source array , want follow pattern store in arrays.
array ( [0] => 15 [1] => 42 [2] => 55 [3] => 42 [4] => 23 [5] => 15 [6] => 38 [7] => 40 [8] => 53 [9] => 10 [10] => 15 )
thanks.
use loops :
$array = array ( [0] => 15 [1] => 42 [2] => 55 [3] => 42 [4] => 23 [5] => 15 [6] => 38 [7] => 40 [8] => 53 [9] => 10 [10] => 15 ) $x = {}; $y = {}; $step = 0; ($i=0; $i < count($array); $i = $i){ if ($step == 0){ array_push($x, $array[$i]); $i = $i + 1; } else { array_push($y, $array[$i]); array_push($y, $array[$i+1]); array_push($y, $array[$i+2]); array_push($y, $array[$i+3]); $i = $i + 4; } }
dont forget sure these steps 1-2-3-4 possible. array 10/15/20 long!
else php return (silecent) error.
Comments
Post a Comment