Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check an array for an existing element.

Status
Not open for further replies.

chrisjwray

Programmer
Jan 17, 2005
9
CA
Hello everybody.
Is there a function to check an array to see if it contains a specific element.
I basically need to check the $_GET array to see if a value has been passed, if it hasn't I need to use a default value. At present I get an error if I try to reference an element in the arry which doesnt exist as it may not have neeb passed to the page.

Thanks in advance

Chris W
 
Sorry I solved this myself, just checked for a null.
Code:
if ($_GET['bob'] == null) echo "No argument passed";

I feel kinda stupid now.
 
You could also check
if (isset($_GET['bob']))
to see if the value is set... or my personal favorite

if (!isset($_GET['bob']) || '' == trim($_GET['bob']))

That way you catch pretty much everything

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top