Sterling Hughes wrote: >>Sterling Hughes wrote: >> >> >>>>Hmm sounds a bit weird to me but if it's really useful than it's OK :) >>>> >>>> >>>> >>> I have to agree, and its really not that hard to implement in user >>> space:: >>> >>> function count_recursive($ar) { >>> $total = 0; >>> >>> foreach ($ar as $e => $val) { >>> if (is_array($val)) { >>> $total += count_recursive($val); >>> } >>> else { >>> $total++; >>> } >>> } >>> >>> return $total; >>> } >>> >>> To me its seems like YACFA (Yet another confusing function >>> argument).
Forgot to read this line :) PECL array module? >>> >>> -Sterling >>> >>> >> >>It's not hard, but it could be very *slow*... >>Loop and function call in PHP script is slow in general :) >>Since it's a O(n), so it may be okay to be slow, though. >> >> > > Well, yeah, but then let's just make PHP a templating engine and > write all our logic in C & C++!! PHP has evolved to the point where > I think its ok to code a majority of the business logic in PHP > instead of C. > > A performance critical script wouldn't do a recursive count anyhow, > it just wouldn't make sense. > > -Sterling I agree. However some users want to count huge array with PHP. I cannot believe there are users use more than 100MB array, but there are. Anyway, I would like to see better performance for loops by default. (performance with ZendOptimizer) It helps array operations a lot. I vote 0 for this function ;) -- Yasuo Ohgaki > > >>-- >>Yasuo Ohgaki >> >> >>>>Andi >>>> >>>> >>>>At 06:54 PM 1/9/2002 +0100, [EMAIL PROTECTED] wrote: >>>> >>>> >>>>>On Wed, 9 Jan 2002, Andi Gutmans wrote: >>>>> >>>>> >>>>> >>>>>>Why is this useful? >>>>>> >>>>>> >>>>>To count the nodes in a tree: >>>>> >>>>>$ar = array ( >>>>> "child1" => array ("child2", "child3", "child4"), >>>>> "child5" => array ("child6", "child7", "child8") >>>>> ); >>>>> >>>>>(maybe a louzy example, but you should get the idea :) >>>>> >>>>>Derick >>>>> >>>>> >>>>> >>>>>>At 06:50 PM 1/9/2002 +0100, [EMAIL PROTECTED] wrote: >>>>>> >>>>>> >>>>>>>On Wed, 9 Jan 2002, Andi Gutmans wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>>Was this in 4.1.1? >>>>>>>> >>>>>>>> >>>>>>>No, only on the 4.2.0 branch. >>>>>>> >>>>>>>Derick >>>>>>> >>>>>>> >>>>>>> >>>>>>>>At 06:49 PM 1/9/2002 +0100, [EMAIL PROTECTED] wrote: >>>>>>>> >>>>>>>> >>>>>>>>>On Wed, 9 Jan 2002, Andi Gutmans wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>>Isn't this the function we decided to nuke? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>Nope, that was is_array_multidimensional(). I'll check if it's >>>>>>>>> >>>>>>>>> >>>>>nuked, is >>>>> >>>>> >>>>>>>>>not, I'll nuke it. >>>>>>>>> >>>>>>>>>Derick >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>>Andi >>>>>>>>>> >>>>>>>>>>At 04:03 PM 1/9/2002 +0000, Derick Rethans wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>>derick Wed Jan 9 11:03:36 2002 EDT >>>>>>>>>>> >>>>>>>>>>>Modified files: >>>>>>>>>>> /php4/ext/standard array.c >>>>>>>>>>> /php4/ext/standard/tests/array count_recursive.phpt >>>>>>>>>>>Log: >>>>>>>>>>>- Fix bug introduced in earlier patch >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>Index: php4/ext/standard/array.c >>>>>>>>>>>diff -u php4/ext/standard/array.c:1.151 >>>>>>>>>>> >>>>>>>>>>> >>>>>>>php4/ext/standard/array.c:1.152 >>>>>>> >>>>>>> >>>>>>>>>>>--- php4/ext/standard/array.c:1.151 Sat Dec 29 15:59:59 2001 >>>>>>>>>>>+++ php4/ext/standard/array.c Wed Jan 9 11:03:34 2002 >>>>>>>>>>>@@ -21,7 +21,7 @@ >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>+----------------------------------------------------------------------+ >>>>> >>>>> >>>>>>>>>>>*/ >>>>>>>>>>> >>>>>>>>>>>-/* $Id: array.c,v 1.151 2001/12/29 20:59:59 derick Exp $ */ >>>>>>>>>>>+/* $Id: array.c,v 1.152 2002/01/09 16:03:34 derick Exp $ */ >>>>>>>>>>> >>>>>>>>>>>#include "php.h" >>>>>>>>>>>#include "php_ini.h" >>>>>>>>>>>@@ -260,11 +260,16 @@ >>>>>>>>>>> if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, >>>>>>>>>>> >>>>>>>>>>> >>>>>"z|l", >>>>> >>>>> >>>>>>>>>>>&array, &mode) == FAILURE) >>>>>>>>>>> return; >>>>>>>>>>> >>>>>>>>>>>- if (Z_TYPE_P(array) == IS_ARRAY) { >>>>>>>>>>>- RETURN_LONG (php_count_recursive (array, mode)); >>>>>>>>>>>- } else { >>>>>>>>>>>- /* return 1 for non-array arguments */ >>>>>>>>>>>- RETURN_LONG(1); >>>>>>>>>>>+ switch (Z_TYPE_P(array)) { >>>>>>>>>>>+ case IS_NULL: >>>>>>>>>>>+ RETURN_LONG(0); >>>>>>>>>>>+ break; >>>>>>>>>>>+ case IS_ARRAY: >>>>>>>>>>>+ RETURN_LONG (php_count_recursive (array, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>mode)); >>>>>>> >>>>>>> >>>>>>>>>>>+ break; >>>>>>>>>>>+ default: >>>>>>>>>>>+ RETURN_LONG(1); >>>>>>>>>>>+ break; >>>>>>>>>>> } >>>>>>>>>>>} >>>>>>>>>>>/* }}} */ >>>>>>>>>>>Index: php4/ext/standard/tests/array/count_recursive.phpt >>>>>>>>>>>diff -u php4/ext/standard/tests/array/count_recursive.phpt:1.1 >>>>>>>>>>>php4/ext/standard/tests/array/count_recursive.phpt:1.2 >>>>>>>>>>>--- >>>>>>>>>>> >>>>>>>>>>> >>>>>>>php4/ext/standard/tests/array/count_recursive.phpt:1.1 Sat Dec 29 >>>>>>> >>>>>>> >>>>>>>>>>>16:05:03 2001 >>>>>>>>>>>+++ php4/ext/standard/tests/array/count_recursive.phpt Wed Jan >>>>>>>>>>> >>>>>>>>>>> >>>>>9 >>>>> >>>>> >>>>>>>>>>>11:03:36 2002 >>>>>>>>>>>@@ -4,6 +4,11 @@ >>>>>>>>>>>--GET-- >>>>>>>>>>>--FILE-- >>>>>>>>>>><?php >>>>>>>>>>>+print "Testing NULL...\n"; >>>>>>>>>>>+$arr = NULL; >>>>>>>>>>>+print "COUNT_NORMAL: should be 0, is ".count($arr, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>COUNT_NORMAL)."\n"; >>>>>>> >>>>>>> >>>>>>>>>>>+print "COUNT_RECURSIVE: should be 0, is ".count($arr, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>COUNT_RECURSIVE)."\n"; >>>>>>>>> >>>>>>>>> >>>>>>>>>>>+ >>>>>>>>>>>print "Testing arrays...\n"; >>>>>>>>>>>$arr = array(1, array(3, 4, array(6, array(8)))); >>>>>>>>>>>print "COUNT_NORMAL: should be 2, is ".count($arr, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>COUNT_NORMAL)."\n"; >>>>>>> >>>>>>> >>>>>>>>>>>@@ -23,6 +28,9 @@ >>>>>>>>>>>print "COUNT_NORMAL: should be 2, is ".count(array("a", >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>array("b")))."\n"; >>>>>>>>> >>>>>>>>> >>>>>>>>>>>?> >>>>>>>>>>>--EXPECT-- >>>>>>>>>>>+Testing NULL... >>>>>>>>>>>+COUNT_NORMAL: should be 0, is 0 >>>>>>>>>>>+COUNT_RECURSIVE: should be 0, is 0 >>>>>>>>>>>Testing arrays... >>>>>>>>>>>COUNT_NORMAL: should be 2, is 2 >>>>>>>>>>>COUNT_RECURSIVE: should be 8, is 8 >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>-- >>>>>>>>>>>PHP CVS Mailing List (http://www.php.net/) >>>>>>>>>>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>>>>>>>For additional commands, e-mail: [EMAIL PROTECTED] >>>>>>>>>>>To contact the list administrators, e-mail: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>[EMAIL PROTECTED] >>>>>>> >>>>>>> >>>>>>>>>>-- >>>>>>>>>>PHP CVS Mailing List (http://www.php.net/) >>>>>>>>>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>>>>>>For additional commands, e-mail: [EMAIL PROTECTED] >>>>>>>>>>To contact the list administrators, e-mail: >>>>>>>>>> >>>>>>>>>> >>>>>>>[EMAIL PROTECTED] >>>>>>> >>>>>>> >>>>>>>-- >>>>>>>PHP CVS Mailing List (http://www.php.net/) >>>>>>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>>>For additional commands, e-mail: [EMAIL PROTECTED] >>>>>>>To contact the list administrators, e-mail: >>>>>>>[EMAIL PROTECTED] >>>>>>> >>>>>>> >>>>>-- >>>>>PHP CVS Mailing List (http://www.php.net/) >>>>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>For additional commands, e-mail: [EMAIL PROTECTED] >>>>>To contact the list administrators, e-mail: [EMAIL PROTECTED] >>>>> >>>>> >>>>-- >>>>PHP CVS Mailing List (http://www.php.net/) >>>>To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>For additional commands, e-mail: [EMAIL PROTECTED] >>>>To contact the list administrators, e-mail: [EMAIL PROTECTED] >>>> >>>> >>>> >> >>-- >>PHP Development Mailing List <http://www.php.net/> >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >>To contact the list administrators, e-mail: [EMAIL PROTECTED] >> >> -- Yasuo Ohgaki -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]