bruckerrlb Posted May 7, 2010 Share Posted May 7, 2010 I'm trying to do an array search and return a variable. The Variables I"m trying to test to see if exists are: $day_start = $day."_start"; $day_end = $day; $day_end .= "_end"; The values of these arrays are: //These are results from a database, and the result is something like 2am or 4pm or something along those lines $mon_start = $row['mon_start']; $mon_end = $row['mon_end']; $tue_start = $row['tue_start']; $tue_end = $row['tue_end']; $wed_start = $row['wed_start']; $wed_end = $row['wed_end']; $thur_start = $row['thur_start']; $thur_end = $row['thur_end']; $fri_start = $row['fri_start']; $fri_end = $row['fri_end']; $sat_start = $row['sat_start']; $sat_end = $row['sat_end']; $sun_start = $row['sun_start']; $sun_end = $row['sun_end']; I have my array set up as following $complete_time = array("mon_start" => $mon_start, "mon_end" => $mon_end, "tue_start" => $tue_start, "tue_end" => $tue_end, "wed_start" => $wed_start, "wed_end" => $wed_end, "thur_start" => $thur_start, "thur_end" => $thur_end, "fri_start" => $fri_start, "fri_end" => $fri_end, "sat_start" => $sat_start, "sat_end" => $sat_end, "sun_start" => $sun_start, "sun_end" => $sun_end); Then, I have a while statement, trying to find the variable while($r = array_search($complete_time, $day_start)) { echo "<td>Found something</td><td>$complete_time</td><td>$day_start</td><br />R is $r"; } Nothing seems to be getting printed out, can anyone tell me what I'm doing wrong? Link to comment https://forums.phpfreaks.com/topic/201018-array_search-and-returning-a-variable/ Share on other sites More sharing options...
bruckerrlb Posted May 7, 2010 Author Share Posted May 7, 2010 I should also point out I've also tried if(in_array($day_start, $complete_time)) { echo "Found something"; } yet, nothing gets found.. Link to comment https://forums.phpfreaks.com/topic/201018-array_search-and-returning-a-variable/#findComment-1054686 Share on other sites More sharing options...
bruckerrlb Posted May 7, 2010 Author Share Posted May 7, 2010 Just in case anyone needs to know for the future, I was trying to get the key of an array and return the value, what worked was: if (array_key_exists($day_start, $complete_time)) { $this_val = $complete_time[$day_start]; echo "val is $this_val"; } Link to comment https://forums.phpfreaks.com/topic/201018-array_search-and-returning-a-variable/#findComment-1054723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.