I need to check if $string1
is like $string2
but I dont want it to matter if one text is different than the otherif it starts with the same string. For example I would like
if (admin.example2 == admin.example1)
should return true! What's the best way to do this?
My exact requirement. An if condition to check if any string is starting with admin is present in the array.
if ($client_name like 'admin') {
...
...
}
There is unlimited number of entries in an array. I just want to check if any string is present which start with "admin" is there or not.
According to your new specified requirement, if a string starts with 'admin' can be checked like this:
$your_string = 'admin.test';
if(strcmp(substr($your_string, 0, 5), "admin") == 0)
{
echo 'begins with admin';
} else {
echo 'does not begin with admin';
}
EDIT:
If you have an array of strings, example $array = array("admin.test", "test", "adminHello", "hello")
, you could make a function that checks if the array contains at least one string that begins with admin:
function checkArrayStartsWithAdmin($array)
{
$result = false;
foreach($array as $key => $value)
{
if(strcmp(substr($value, 0, 5), "admin") == 0)
{
$result = true;
break;
}
}
return $result;
}