method indexOf documentation in bbn\X
Searches from start to end.
Example
X::indexOf(['a', 'b', 'c'], 'b');
// (int) 1
X::indexOf(['a', 'b', 'c'], 'b', 2);
// (int) -1
X::indexOf('foobar', 'bar');
// (int) 3
X::indexOf('foobar', 'bar', 4);
// (int) -1
function($subject, $search, int $start = 0)
{
$res = false;
if (is_array($subject)) {
$i = 0;
foreach ($subject as $s) {
if (($i >= $start) && ($s === $search)) {
$res = $i;
break;
}
else{
$i++;
}
}
}
elseif (is_string($subject)) {
$res = strpos($subject, $search, $start);
}
return $res === false ? -1 : $res;
}
Searches from start to end. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions