Jump to content

Recommended Posts

How would I go about checking if a variable equals anything within an array.

 

For instances:

 

$array = ('2009-06-01', '2009-06-02', '2009-06-20', '2006-06-25');
$today = "2009-06-20";

if($today = $array) {
     echo "Today was found within the array";
}

 

I know that won't work but it's what I'm looking to accomplish.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/162798-if-variable-anything-within-an-array/
Share on other sites

Actually I'm going to ask another question that relates to this one. How does one set a while loop results as an array?

 

$dateSelect = "SELECT dates FROM dates_table";

cancelDates = array();
while($row=mysql_fetch_assoc($dateSelect)) 

 

I basically want the dates to be set as an array.

Okay, so if I wanted to check if a date was in that array I would use:

 

if(in_array("2009-06-19", $dates)) { 
$checked = "checked"; 
}

echo $checked;

 

Why am I receiving this:

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.