Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to check if string exist in array in PHP

2 Answers

0 votes
// bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

$arr = array("C", "PHP", "C#", "JAVA");

if (in_array("PHP", $arr))
    echo "Exist"; // Exist
else
    echo "NOT Exist";
    
echo "<br>";
$java = in_array("JAVA", $arr);
if ($java)
    echo "Exist"; // Exist
else
    echo "NOT Exist";
    
echo "<br>";
if (in_array("Visual Basic", $arr))
    echo "Exist";
else
    echo "NOT Exist"; // NOT Exist


/*
run:

Exist
Exist
NOT Exist  
   
*/
   

    


answered Jun 25, 2014 by avibootz
edited Jun 29, 2016 by avibootz
0 votes
// bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

// strict - If the third parameter strict is set to TRUE then 
//          in_array() will check the types of the needle in the haystack.

$a = array('3.14', 13.9, 78.5);

if (in_array('3.14', $a, true))
    echo "3.14 exist with strict <br />";
else
    echo "3.14 Not exist <br />";

if (in_array(13, $a, true)) 
    echo "13.9 exist with strict <br />";
else
    echo "13.9 Not exist <br />";

/*
run:

3.14 exist with strict 
13.9 Not exist 

*/

 



answered Jun 29, 2016 by avibootz

Related questions

3 answers 292 views
1 answer 161 views
161 views asked May 23, 2018 by avibootz
1 answer 192 views
192 views asked Jul 7, 2014 by avibootz
1 answer 157 views
...