PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I check if a variable is of array type?


If you want to check that you are dealing with an array and not a string, then you simply use is_array, like so:

<?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

I tried to query a table and retrieve some data, then I email them to an indivisual person with different data. However, I am only to send the 1st email, but not 2nd email. My query seem that not able to pass the 1st data found and pass it for 2nd time

how a values entered in an array from keyboard?

How can I reverse sort an array keeping the correlation between the index and value?

How do I turn an array into a string?

in .$array->description doesn't work "description" is suppose to stay black and turns colored and is ignored Why?



Custom Search