Jump to content

How find duplicate in array


Pearl

Recommended Posts

 
 
 
 
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 successfully
2015-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>";
}
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.