Pearl Posted February 13, 2015 Share Posted February 13, 2015 You chose 2-bed(s) rooms and they are in hotel- 4 .Kind of room 2 bed(s) 2015-01-13 2015-01-21 Connected successfully2015-01-132015-01-142015-01-152015-01-162015-01-172015-01-182015-01-192015-01-20Kind of room 3 bed(s) 2015-01-13 2015-01-21 Connected successfully 2015-01-132015-01-142015-01-152015-01-162015-01-172015-01-182015-01-192015-01-20Kind of room 2 bed(s) 2015-01-16 2015-01-21 Connected successfully 2015-01-162015-01-172015-01-182015-01-192015-01-20Kind of room 2 bed(s) 2015-01-18 2015-01-21 Connected successfully 2015-01-182015-01-192015-01-20 No duplicates found. Those dates they are arrays it is altogether $result[$x]. I can't find duplicate in array $link = mysql_connect('','', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(); $row["datefrom"]= strtotime( $row["datefrom"]); $row["dateto"] = strtotime($row["dateto"]); // Loop until we reach the last day $result = array(); while ($row["datefrom"] <= $row["dateto"] ) { if (date('N', $row["datefrom"]) <60) { $result[] = date('Y-m-d', $row["datefrom"]); } $row["datefrom"] = strtotime('+1 day', $row["datefrom"]); } $sql="select datefrom, dateto, rooms, count(*) as duplicates from rooms group by datefrom, dateto, rooms order by datefrom, rooms limit $brsoba"; // Show the result // You could loop the array to pretty-print it, or do it within the above loop array_pop($result); sort($result); echo "<pre>"; $arrlength = count($result); for($x = 0; $x < $arrlength; $x++) { echo $result[$x]; echo "<br>"; $test = array('$result[$x]'); $result[$x] = getArrayDups($test); } //$result[$x]= array( $result[$x]); //$result[$x]= array_count_values($result[$x]); // // //foreach( $result[$x] as $result[$x]=>$value) ////echo "$key - <strong>$value</strong> <br />"; // // //{ // } function getArrayDups($array) { $counts = array_count_values($array); return array_filter( $counts, create_function( '$val', 'return($val > 1);' ) ); } // usage test: $test = array('$result[$x]'); $result[$x] = getArrayDups($test); if(count($result[$x])) { echo "<p>You had one or more duplicate entries:</p>\n<ul>\n"; foreach($result[$x] as $entry => $count) { echo "<li>$entry ($count)</li>"; } } else { echo "<p>No duplicates found.</p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/294588-how-find-duplicate-in-array/ Share on other sites More sharing options...
Barand Posted February 14, 2015 Share Posted February 14, 2015 If you want to find overlapping dates then use a query like this SELECT a.room_id as rooma , a.start_date as starta , a.end_date as enda , b.room_id as roomb , b.start_date as startb , b.end_date as endb FROM book a INNER JOIN book b ON a.end_date > b.start_date AND a.start_date < b.end_date AND a.room_id < b.room_id Quote Link to comment https://forums.phpfreaks.com/topic/294588-how-find-duplicate-in-array/#findComment-1505716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.