note 54604 deleted from function.array-slice by cmb
| From: | cmb@php.net | Date: | Sun, 29 Dec 2019 12:29:43 +0000 |
| Subject: | note 54604 deleted from function.array-slice by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213703@lists.php.net to get a copy of this message | ||
Note Submitter: fanfatal at fanfatal dot pl
----
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 ;-)
...