php - short mysql dates array to readable -
i have array of dates contains many dates.
i have placed dates on graph in php, there not enough space on graph.
i want make dates short (i.e samples) placed on graph.
for example
array=(1,2,3,4,5,6,7,8,9,7,8,9,6,5);
after short , sampling should be
1,4,8,8,5
you can loop through array , add nth values new array can use in graph. can use modulo on array keys , use ratio of values number of results whant.
$new_array = array(); $array = array(1,2,3,4,5,6,7,8,9,7,8,9,6,5); $array_count = count($array); $number_of_results = 5; // number of results whant $ratio = ceil($array_count / $number_of_results); foreach ($array $key => $val) { if ( $key % $ratio == 0 ) { $new_array[] = $val; } }
Comments
Post a Comment