note 34965 modified in function.array-sum by vrana

From: Date: Tue, 17 Aug 2004 14:50:08 +0000
Subject: note 34965 modified in function.array-sum by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79895@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 : <?php 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_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 http://php.net/manual/en/function.array-sum.php

« previous php.notes (#79895) next »