note 34659 added to function.array-sum
| From: | corto at maichiuso dot com | Date: | Sat, 02 Aug 2003 21:04:34 +0000 |
| Subject: | note 34659 added to function.array-sum | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53224@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.array-sum.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34659
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34659&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34659&report=yes