Compare two arrays with Array_diff () why only a different element is returned

Source: Internet
Author: User
Compare two arrays using Array_diff () why only a different element is returned?
I take out the values of the same fields in the different tables in the database in two different arrays, using Array_diff () to find the elements in array 1 instead of the array 2, why only a different element is returned?
The code is as follows:
Error_reporting (E_all&~e_notice);
Header (' content-type:text/html; Charset=utf-8 ');
Date_default_timezone_set (' Asia/shanghai ');
Require_once ("init.php");
$sql = "SELECT * from Dev_property";
$res =mysql_query ($sql) or Die (Mysql_error ());
$num _rows=mysql_num_rows ($res);
while ($sn =mysql_fetch_array ($res))
{
$prime =array ();
$prime []= $sn ["Serial_number"];
for ($i =0; $i <>
{
echo $prime [$i];
echo "
";
}

}
echo "
";
$starttime = ' 08:25:00 ';
$endtime = ' 23:35:00 ';
$sql = "SELECT * from Data where time>= '". Date (' y-m-d '). ' '. $starttime. ' and time<= '. Date (' y-m-d '). ' '. $endtime. ' ";
$result =mysql_query ($sql) or Die (Mysql_error ());
while ($date =mysql_fetch_array ($result))
{
$num _rows1=mysql_num_rows ($result);


$a =array ();
$a []= $date ["Serial_number"];
for ($i =0; $i <>
{
echo $a [$i];
echo "
";
}


echo "
";

}
$diff =array_diff ($prime, $a);
for ($i =0; $i <>
echo $diff [$i];
echo "
";
echo count ($diff);
echo "
";
?>
Execution Result:
Array $prime
862118028862461
862118028862462
862118028862463
862118028862464
Array $ A
862118028862461
Results
862118028862464
1
What I meant to return was,
862118028862462
862118028862463
862118028862464
Now only returns 862118028862464, why?
------to solve the idea----------------------
You are $diff =array_diff ($prime, $a); Print the array before
Print_r ($prime);
Print_r ($a);
$diff =array_diff ($prime, $a);
Look what it is.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.