note 46762 added to function.array-search

From: Date: Fri, 22 Oct 2004 12:01:21 +0000
Subject: note 46762 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-78940@lists.php.net to get a copy of this message
There is no function to count the occurences of needle in haystack, so I made my own one... <?php function array_match($needle, $haystack) { if( !is_array($haystack) ) return false; $i = 0; while( (in_array( $needle, $haystack )) != FALSE ) { $i++; $haystack[array_search($needle, $haystack)] = md5($needle); reset($haystack); } return $i; } ?> I know it's a bit crappy, but don't ask me too much, I'm still only 13... ;) ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46762 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46762&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46762&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78940) next »