How can I find an highlight a string in a foreach?
This loops through all users of my database and I want to find all lets say $um.
$um = "Um";
foreach($users as $user){
# find here the string um or something
echo $user;
}
How do I accomplish this?
In reality, I would do this in the query.. ..but
$um = "Um";
foreach($users as $user){
if(strpos($user,$um) !== false){
echo $user;
}
}
strpos() returns a string position, so a return value of '0' would be a match at the beginning of the string. So, check for 'not false' http://php.net/manual/en/function.strpos.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With