Q: Compare two arrays in mysql and php i have this small loop of time in day. 
$datum = $date_final;
$iTimestamp = mktime(8,0,0,1,1,2014);
for ($i = 1; $i < $den; $i++) {
    $vypis = $datum.' '.date('H:i:s', $iTimestamp) . "\n<br />";
    $iTimestamp += $sekundy;
    echo $vypis;
}

It will echo something like this:
2014-06-02 10:00:00 
2014-06-02 10:30:00 
2014-06-02 11:00:00 
2014-06-02 11:30:00 
2014-06-02 12:00:00 
2014-06-02 12:30:00 
2014-06-02 13:00:00 
2014-06-02 13:30:00 
2014-06-02 14:00:00 
2014-06-02 14:30:00 
2014-06-02 15:00:00 
2014-06-02 15:30:00 
2014-06-02 16:00:00 
2014-06-02 16:30:00 
2014-06-02 17:00:00 

i have second script - mysql query loop
$data = mysql_query ("select * from evenement");
$zaznam = mysql_fetch_array ($data);
while($zaznam = mysql_fetch_array ($data))
{
echo $zaznam["start"];
}

it give me similar results :
2014-05-25 19:30:00
2014-05-28 13:30:00
2014-04-21 09:30:00
2014-05-20 11:00:00
2014-05-28 13:00:00
2014-04-27 00:00:00
2014-05-21 12:00:00
2014-05-22 11:30:00
2014-05-20 13:00:00
2014-05-22 11:30:00
2014-05-28 15:30:00
2014-05-28 13:00:00

Im trying to write a script which compare every single echo $vypis with all results in mysql query. After that i can easily put condition here - if it is not in mysql - echo "Free" and if it is in mysql echo "....". I think i have to use foreach maybe. 
I need compare one result from php loop with all results from DB, apply conditions and next one result, compare to all ..... 
Have you any ideas guys ? I need small help here.

A: to compare php array value with all sql values do like below (i hope this is what you are asking about)
for ($i = 1; $i < $den; $i++) {
    $vypis = $datum.' '.date('H:i:s', $iTimestamp) . "\n<br />";
    $iTimestamp += $sekundy;
    $arr1[]=$vypis;//store php values in first array
}


//and in php

while($zaznam = mysql_fetch_array ($data))
{
 $arr2[] = $zaznam["start"];//store query values in second array
}


//and now use forloops

foreach($arr1 as $k=>$val)
{
  if(in_array($val,$arr2))
  {
   echo '...';
  }
 else
 {
  echo 'Free';
 }
}


A: Store the results in an array for php
$phpDateArray=array();
$datum = $date_final;
$iTimestamp = mktime(8,0,0,1,1,2014);
for ($i = 1; $i < $den; $i++) {
    $vypis = $datum.' '.date('H:i:s', $iTimestamp) . "\n<br />";
    $iTimestamp += $sekundy;
    $phpDateArray[]=$vypis;
}

Same for the query:
$mysqlDataArray=array();
$data = mysql_query ("select * from evenement");
$zaznam = mysql_fetch_array ($data);
while($zaznam = mysql_fetch_array ($data))
{
    $mysqlDataArray[]=$zaznam["start"];
}

And search with array_search()
foreach($phpDataArray as $key=>$time){
    if(array_search($time, $mysqlDataArray)===FALSE){
        echo $time. " free";
    } else {
        echo $time. " ...";
    }
}

This could be optimized, but i followed your style.
An other options with array_merge would be like this:
$phpDateArray=array();
$datum = $date_final;
$iTimestamp = mktime(8,0,0,1,1,2014);
for ($i = 1; $i < $den; $i++) {
    $vypis = $datum.' '.date('H:i:s', $iTimestamp) . "\n<br />";
    $iTimestamp += $sekundy;
    $phpDateArray[$vypis]="free";
}

$mysqlDataArray=array();
$data = mysql_query ("select * from evenement");
$zaznam = mysql_fetch_array ($data);
while($zaznam = mysql_fetch_array ($data))
{
    $mysqlDataArray[$zaznam["start"]]="start";
}

$resultArray = array_merge($phpDateArray, $mysqlDataArray);
foreach($resultArray as $time=>$value){
    echo $value;
}


A: If you only want to find the differences you can use  array_diff. But if you want to check each one of the element you can do as @Feroz Akbar says

A: Using a temp table could be done like this:-
<?php

$datum = $date_final;
$iTimestamp = mktime(8,0,0,1,1,2014);
for ($i = 1; $i < $den; $i++) 
{
    $vypis = $datum.' '.date('H:i:s', $iTimestamp) . "\n<br />";
    $aDate[] = $vypis;
    $iTimestamp += $sekundy;
    echo $vypis;
}

$sql = "CREATE TEMPORARY TABLE tmp_date (aDate DATETIME, INDEX aDate(aDate))";
$data = mysql_query ($sql);
$sql = "INSERT INTO tmpdate(aDate) VALUES ('".implode("','", $aDate)."')";
$data = mysql_query ($sql);

$sql = "SELECT a.start
        FROM evenement a
        INNER JOIN tmp_date b
        ON a.start = b.aDate";
$data = mysql_query($sql);
$zaznam = mysql_fetch_array ($data);
echo "List if start dates that are in the generated list of dates\r\n";
while($zaznam = mysql_fetch_array ($data))
{
    echo $zaznam["start"]."\r\n";
}

$sql = "SELECT a.start
        FROM evenement a
        LEFT OUTER JOIN tmp_date b
        ON a.start = b.aDate
        WHERE b.aDate IS NULL";
$data = mysql_query($sql);
$zaznam = mysql_fetch_array ($data);
echo "List if start dates that are not in the generated list of dates\r\n";
while($zaznam = mysql_fetch_array ($data))
{
    echo $zaznam["start"]."\r\n";
}

$sql = "SELECT a.aDate
        FROM tmp_date b
        INNER JOIN evenement a
        ON a.start = b.aDate
        WHERE a.start IS NULL";
$data = mysql_query($sql);
$zaznam = mysql_fetch_array ($data);
echo "List if generated dates that are not in the list of start dates\r\n";
while($zaznam = mysql_fetch_array ($data))
{
    echo $zaznam["start"]."\r\n";
}

?>

The temp table is only there for the length of time the database connection exists (and only for that database connection). Easy to create it and insert the rows to it as you can see.
The rest of the script is putting out the dates, either as ones that in both lists, in one list or in the other list.
