Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if string has a specific number, not digit

This is what I have:

$a = '3,24,57';

if (strpos($a, '7') == true) {
    echo 'number found';
}

The code will return "number found" because of the number 57 but there is no number 7 in the string. How can I make this work in a way that will return true only if the string is like this: "3,7,24,57"

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just try like this.

$array = explode(",", $a);
if (in_array("7", $array )) {
    echo 'number found';
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading