note 54604 added to function.array-slice
| From: | fanfatal at fanfatal dot pl | Date: | Fri, 08 Jul 2005 22:09:10 +0000 |
| Subject: | note 54604 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91702@lists.php.net to get a copy of this message | ||
Hmm ... i wrote an usefull function whitch is such like strpos but it works on arrays ;]
<?php
/*
* Find position of first occurrence of a array
*
* @param array $haystack
* @param array $needle
* @return int
* @author FanFataL
*/
function array_pos($haystack, $needle) {
$size = count($needle);
$sizeh = count($haystack);
if($size > $sizeh) return false;
$scale = $sizeh - $size + 1;
for($i = 0; $i < $scale; $i++)
if($needle === array_slice($haystack, $i, $size))
return $i;
return false;
}
// Sample:
$a = array('aa','bb','cc','dd','ee');
$b = array('cc','dd');
$pos = array_pos($a, $b);
?>
Greatings ;-)
...
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54604
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54604&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54604&report=yes
Search -- http://master.php.net/manage/user-notes.php