0

I have an array of dates that contains many dates.

I have placed all dates on the graph in php, but there is not enough space on the graph.

I want to make the dates short (i.e samples) to be placed on the graph.

For example

 array=(1,2,3,4,5,6,7,8,9,7,8,9,6,5);

After short and sampling it should be

 1,4,8,8,5
Java Devil
  • 10,629
  • 7
  • 33
  • 48
  • What are you really asking? There's no way to identify based on the information you've given what you want. Also, what have you tried? – Ohgodwhy Jul 21 '13 at 20:21

1 Answers1

0

You can loop through array and add nth values to new array that You can use in Your graph. You can use modulo on array keys for that and use ratio of values to number of results You 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 you whant
$ratio = ceil($array_count / $number_of_results);

foreach ($array as $key => $val) {
    if ( $key % $ratio == 0 ) {
        $new_array[] = $val;    
    }
}
adam187
  • 3,193
  • 21
  • 15