note 34659 deleted from function.array-sum by didou

From: Date: Sun, 03 Aug 2003 10:06:32 +0000
Subject: note 34659 deleted from function.array-sum by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53243@lists.php.net to get a copy of this message
Note Submitter: corto@maichiuso.com ---- This function group array like mysql function group_array() { $args = func_get_args(); $marray = array_shift($args); foreach ($marray as $marray_item) { for ($i = 1; $i<count($args); $i++) { $group_array[$marray_item[$args[0]]] [$args[$i]] += $marray_item[$args[$i]];} } return $group_array; } syntax: $array_result = group_array($my_array , 'col1' [, 'col2' [, 'col3']]]...); __________ explanation: $my_array is the array you want to group, 'col1' is the name of the column you want group by, 'col2', 'col3' .... the names of the column you want sum _______ example: imy_array Array ( [0] => Array ( [codice] => 8 [codice_uid] => 104 [codice_utente] => cproma [funzione] => fib_giocatore_sel [time_stamp] => 20030801155738 [session_id] => d172aa34b9f64a7e88ceb28eb4175c [tipo_tariffa] => T [prezzo_unit] => 0.5 [utilizzo] => 0.066666666666667 [prezzo] => 0.033333333333333 ) ...... } array_result Array ( [fib_giocatore_sel] => Array ( [utilizzo] => 0.066666666666667 [prezzo] => 0.033333333333333 ) ... } that should be enough :) hope it helps you.. corto corto@maichiuso.com

« previous php.notes (#53243) next »