Determine whether a string of multiple numbers contains a unique number

WBOY
Release: 2016-08-08 09:07:05
Original
1495 people have browsed it

$str=10,11,12,13,14,15,16,17,18,19;
$str2=9;

I want to determine whether this $str2 is in $str, but I can still find it using PHP’s own function strpos because 19 also contains 9. The effect I want is to judge whether each string is equal to this $str2 by commas. Please help me. Thank you. Endless^_^

Reply content:

$str=10,11,12,13,14,15,16,17,18,19;
$str2=9;

I want to determine whether this $str2 is in $str, but I can still find it using PHP’s own function strpos because 19 also contains 9. The effect I want is to judge whether each string is equal to this $str2 by commas. Please help me. Thank you. Endless^_^

First separate the elements into an array by commas and use the explode() function. Then use the in_array() function to find out whether there is an element 9.

Remove the separator (comma) to only one element, and then use stripos. Note that the possible position is 0, so use === false

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!