note 21776 added to function.each

From: Date: Sun, 26 May 2002 14:13:19 +0000
Subject: note 21776 added to function.each
Groups: php.notes 
Request: Send a blank email to php-notes+get-31048@lists.php.net to get a copy of this message
I wrote a short and pretty simple script to search through associative arrays for some value in the values, heres a simplifyed example of it: <?php $foo['bob'] = "bob is ugly"; $foo['bill'] = "bill is rich"; $foo['barbie'] = "barbie is cute"; $search = "rich"; echo "searching the array foo for $search:<br>"; reset ($foo); while (list ($key, $val) = each ($foo)) { if (preg_match ("/$search/i", $val)) { print "A match was found in $key.<br />"; } else { print "A match was not found in $key.<br />"; } } ?> will output: Searching the array foo for rich: A match was not found in bob A match was found in bill A match was not found in barbie -- http://www.php.net/manual/en/function.each.php http://master.php.net/manage/user-notes.php?action=edit+21776 http://master.php.net/manage/user-notes.php?action=delete+21776 http://master.php.net/manage/user-notes.php?action=reject+21776

« previous php.notes (#31048) next »