I need to make a loop that checks if an array ( $array ), contains a string ( 'thisisaverylongstring' ), that contains another string ( 'isavery' ).
How would I write this in valid PHP?
If it is a simple as you say it is, you can use stripos (case insensitive string search):
foreach ($array as $element) {
if (stripos($element, 'isavery') !== false) {
echo 'Found it!';
break;
}
}
I don't know what's your actual requirement is but as from my understanding the following function could work
function checkInArray($array, $val)
{
if(in_array($val,$array))
return true;
}
function checkvalinarray($array2D, $val1, $val2)
{
foreach($array2D as $array1D)
{
if(checkInArray($array1D,$val2))
return true;
}
}
in_array()andarray_search()functions ?'thisisaverylongstring'will contain'isavery'. So why don't you look for the short one only?