note 110240 deleted from function.count by danbrown

From: Date: Thu, 06 Dec 2012 15:02:00 +0000
Subject: note 110240 deleted from function.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192360@lists.php.net to get a copy of this message
Note Submitter: espertalhao04 at hotmail dot com ---- jezed at email dot cz you gave a great example, but you missed one particular thing: performance... <?php $data = array( "apples" => array("red", "yellow", "pineapples"), "bananas" => array("small", "medium", "big"), "vegs" => array("potatoes", "carrots", "onions") ); $rows = count($data,0); $cols = (count($data,1)/count($data,0))-1; print "There are {$rows} rows and {$cols} columns in the table!"; ?> is slower than <?php $data = array( "apples" => array("red", "yellow", "pineapples"), "bananas" => array("small", "medium", "big"), "vegs" => array("potatoes", "carrots", "onions") ); $cols = (count($data,1)/($rows = count($data,0)))-1; print "There are {$rows} rows and {$cols} columns in the table!"; ?> in this way, you will get BOTH $cols and $rows and you reduced the code in 1 count... in terms of performance with a 3x3 array, it's no problem, but a 50x50 array, it might hit performance...

« previous php.notes (#192360) next »