PHPverse 2025

Voting

: min(seven, two)?
(Example: nine)

The Note You're Voting On

akarmenia at gmail dot com
14 years ago
My version of strpos with needles as an array. Also allows for a string, or an array inside an array.

<?php
function strpos_array($haystack, $needles) {
if (
is_array($needles) ) {
foreach (
$needles as $str) {
if (
is_array($str) ) {
$pos = strpos_array($haystack, $str);
} else {
$pos = strpos($haystack, $str);
}
if (
$pos !== FALSE) {
return
$pos;
}
}
} else {
return
strpos($haystack, $needles);
}
}

// Test
echo strpos_array('This is a test', array('test', 'drive')); // Output is 10

?>

<< Back to user notes page

To Top