note 34965 modified in function.array-sum by pollita

From: Date: Wed, 13 Aug 2003 15:32:25 +0000
Subject: note 34965 modified in function.array-sum by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54083@lists.php.net to get a copy of this message
Hi people, if someone is searching a function that works also with multimension array, i suggest this : function cw_array_count($a) { if(!is_array($a)) return $a; foreach($a as $key=>$value) $totale += cw_array_count($value); return $totale; } $a[0][E][PS][P][a1]=1; $a[0][E][PS][P][a2]=2; $a[0][E][PJ][P][a2]=2; $a[1][E][PS][E][a3]=3; echo cw_array_count($a[0]); or echo cw_array_count($a[0][E]); Bye, Bye. R.Martina --was-- Hi people, if someone is searching a function that works also with multimension array, i suggest this : function cw_array_sum($a) { if(!is_array($a)) return $a; foreach($a as $key=>$value) $totale += cw_array_count($value); return $totale; } $a[0][E][PS][P][a1]=1; $a[0][E][PS][P][a2]=2; $a[0][E][PJ][P][a2]=2; $a[1][E][PS][E][a3]=3; echo cw_array_count($a[0]); or echo cw_array_count($a[0][E]); Bye, Bye. R.Martina http://www.php.net/manual/en/function.array-sum.php

« previous php.notes (#54083) next »