JJohnsenDK Posted December 21, 2007 Share Posted December 21, 2007 Hey I have this function which checks if an number is in a array. What i am using this for is to check if a periode of days is booked in a calendar. The function works fine if i just manually write the numbers into the array. But i want to use the variable i create with the numbers. The wierd thing is that this works if i make a foreach on the array. The in_array() function just wont work when i declare the array with an variable. Here is the code: function checkBusyDate($day, $month, $year){ $date = $day."/".$month."/".$year; $query = mysql_query("SELECT toa FROM calendar WHERE froma = '$date'"); $data = mysql_fetch_array($query); $from = $day; $to = substr($data['toa'], 0, 2); while($from < $to){ $numForArray .= $from.", "; $from++; } $numForArray .= $to; $array = array($numForArray); if(in_array(25, $array, true)){ echo "Yep its there."; }else{ echo "Nopez, sry"; } } checkBusyDate(24, 12, 2007); Does'nt in_array() support what im trying to do or whats wrong? Link to comment https://forums.phpfreaks.com/topic/82676-solved-in_array-problem/ Share on other sites More sharing options...
chigley Posted December 21, 2007 Share Posted December 21, 2007 $array = array($numForArray) would give the array only one value. Try this: <?php function checkBusyDate($day, $month, $year){ $date = $day."/".$month."/".$year; $query = mysql_query("SELECT toa FROM calendar WHERE froma = '$date'"); $data = mysql_fetch_array($query); $from = $day; $to = substr($data['toa'], 0, 2); $array = array(); while($from < $to){ $array[] = $from; $from++; } $array[] = $to; if(in_array(25, $array)){ echo "Yep its there."; }else{ echo "Nopez, sry"; } } checkBusyDate(24, 12, 2007); ?> Link to comment https://forums.phpfreaks.com/topic/82676-solved-in_array-problem/#findComment-420488 Share on other sites More sharing options...
JJohnsenDK Posted December 21, 2007 Author Share Posted December 21, 2007 works!... thanks alot mate ... merry xmas Link to comment https://forums.phpfreaks.com/topic/82676-solved-in_array-problem/#findComment-420491 Share on other sites More sharing options...
chigley Posted December 21, 2007 Share Posted December 21, 2007 No problem - merry Xmas to you too! Link to comment https://forums.phpfreaks.com/topic/82676-solved-in_array-problem/#findComment-420492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.