How do I check if a variable is of array type?
<?php
$array = (1,2,3);
if(is_array($array)) { echo "Look, an array"; } else { echo "You might be stringing me along"; }
//Look, an array
?>
Comments on this Question/Answer
Why would this function ever be useful?By: Dave Frost, 20 Nov 2008 07:43:02
It is useful precisely when you want to know whether you are dealing with an array or not, as the name suggests! This is useful because clearly you will want to treat the contents of an array differently to, for instance, a string.
By: Moderator, 20 Nov 2008 07:49:23
Reply to comments / post your own comment >>>
ASK A QUESTION
More arrays PHP Questions
How can I reset an array in PHP?how do i send the information from one page to another page using post method.
How do I remove the first element from an array?
How can I create an array of numbers easily?
I have an array of a hundred or so lines, each line has data with "|" separated values. I need to scan through this array, and select the line whose first 5 characters matches a text string. Any ideas or questions?
