note 57835 added to function.array-chunk

From: Date: Sat, 15 Oct 2005 17:58:24 +0000
Subject: note 57835 added to function.array-chunk
Groups: php.notes 
Request: Send a blank email to php-notes+get-97072@lists.php.net to get a copy of this message
This function takes each few elements of an array and averages them together. It then places the averages in a new array. It is used to smooth out data. For example lets say you have a years worth of hit data to a site and you want to graph it by the week. Then use a bucket of 7 and graph the functions output. function array_bucket($array, $bucket_size) // bucket filter { if (!is_array($array)) return false; // no empty arrays $buckets=array_chunk($array,$bucket_size); // chop up array into bucket size units foreach ($buckets as $bucket) $new_array[key($buckets])=array_sum($bucket)/count($bucket); return $new_array; // return new smooth array } ---- Manual Page -- http://www.php.net/manual/en/function.array-chunk.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57835 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57835&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57835&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97072) next »