note 28020 modified in function.strpos by aidan

From: Date: Thu, 10 Jun 2004 07:01:33 +0000
Subject: note 28020 modified in function.strpos by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70820@lists.php.net to get a copy of this message
Description: array straipos ( string haystack, array needle [, int offset]) Returns an indexed array of the item from the array 'needle' that occurs first in the haystack, with item 0 being its position in the 'haystack', and item 1 being the item number of the item found. If none of the items are found, it returns false. <?php function straipos($haystack,$array,$offset=0) { $occ = Array(); for ($i = 0;$i<sizeof($array);$i++) { $pos = strpos($haystack,$array[$i],$offset); if (is_bool($pos)) continue; $occ[$pos] = $i; } if (sizeof($occ)<1) return false; ksort($occ); reset($occ); list($key,$value) = each($occ); return array($key,$value); } ?> --was-- Description: array straipos ( string haystack, array needle [, int offset]) Returns an indexed array of the item from the array 'needle' that occurs first in the haystack, with item 0 being its position in the 'haystack', and item 1 being the item number of the item found. If none of the items are found, it returns false. function straipos($haystack,$array,$offset=0) { $occ = Array(); for ($i = 0;$i<sizeof($array);$i++) { $pos = strpos($haystack,$array[$i],$offset); if (is_bool($pos)) continue; $occ[$pos] = $i; } if (sizeof($occ)<1) return false; ksort($occ); reset($occ); list($key,$value) = each($occ); return Array($key,$value); } http://www.php.net/manual/en/function.strpos.php

« previous php.notes (#70820) next »