note 37984 added to function.count-chars

From: Date: Wed, 03 Dec 2003 21:27:52 +0000
Subject: note 37984 added to function.count-chars
Groups: php.notes 
Request: Send a blank email to php-notes+get-61362@lists.php.net to get a copy of this message
Here's a very simple frequency counter I use most often in statistical apps: function count_item(&$freq, $item, $inc = 1) { if (! is_array($freq)) { $freq = array (); } $freq[$item] = (isset($freq[$item]) ? ($freq[$item] += $inc) : $inc); return true; } The point here is this function saves you the isset() check on the assignment every single time you wish to count frequency. This is important if you care about getting rid of all of PHPs warnings, including those about uninitialized variables. ---- Manual Page -- http://www.php.net/manual/en/function.count-chars.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37984 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37984&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37984&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61362) next »