How to check whether a variable is an array in PHP

3 Answers

0 votes
$arr = array('php', 'C++', 'Java');

echo is_array($arr) ? 'Array' : 'Not Array';


/*
run: 

Array

*/

 



answered Jun 30, 2016 by avibootz
0 votes
$s = 'php, C++, Java';

echo is_array($s) ? 'Array' : 'Not Array';


/*
run: 

Not Array 

*/

 



answered Jun 30, 2016 by avibootz
0 votes
$array = [100, 300];

if (gettype($array) === 'array')
    echo "true";


 
/*
run: 

true
  
*/ 

 



answered Sep 11, 2017 by avibootz

Related questions

1 answer 228 views
8 answers 430 views
4 answers 221 views
2 answers 205 views
1 answer 213 views
2 answers 264 views
3 answers 292 views
...