Check if a string contains a certain number

前端 未结 5 1965
死守一世寂寞
死守一世寂寞 2021-01-14 18:14

I have a string

8,7,13,14,16

Whats the easiest way to determine if a given number is present in that string?

$numberA = \"1         


        
5条回答
  •  天命终不由人
    2021-01-14 18:37

    
    

    …will return whether '13' is in the string.

    Just to elaborate: explode turns the string into an array, splitting it at each ',' in this case. Then, in_array checks if the string '13' is in the resulting array somewhere.

提交回复
热议问题