Variable is a String or an Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
avivm3
Forum Commoner
Posts: 31
Joined: Mon Jul 12, 2010 5:29 pm

Variable is a String or an Array

Post by avivm3 »

This seems like a really obvious question, but I'm tired of struggling for the answer.

I have an IF statement that I want to trigger ONLY if the variable I provide is a single value (Number or String). I DON'T want it running if the variable is an Array. What statement should I use to check if it's an array, and won't error out if it's not?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Variable is a String or an Array

Post by cpetercarter »

The functions which test the type of a variable are is_array(), is_int(), is_float(), is_string(), is_object(). Between them I think you can achieve what you want!
Last edited by cpetercarter on Wed Aug 11, 2010 1:27 am, edited 1 time in total.
avivm3
Forum Commoner
Posts: 31
Joined: Mon Jul 12, 2010 5:29 pm

Re: Variable is a String or an Array

Post by avivm3 »

Perfect. Thanks!
Post Reply