How to check if a value exists in array with PHP

2 Answers

0 votes
$array = ['PHP', 'Java', 'Python'];

$e = in_array('PHP', $array);

if ($e)
    echo "true";

 
/*
run: 

true
  
*/  

 



answered Sep 11, 2017 by avibootz
0 votes
$array = ['PHP', 'Java', 'Python'];

$pos = array_search('Python', $array);
if ($pos !== false) 
    echo "Python found at index: $pos";


 
/*
run: 

Python found at index: 2
  
*/   

 



answered Sep 11, 2017 by avibootz

Related questions

1 answer 143 views
1 answer 203 views
2 answers 276 views
6 answers 551 views
1 answer 196 views
1 answer 144 views
...