Such as:
$grade = Array( [0] => Array ( [course_name] => 大学英语(综合)-1 [course_strid] => College English (Comprehensive)-1 [credit] => 2 [course_nature] => 必修 [grade] => 70.0 [year] => 2013-2014 [term] => 1 [user_id] => 1034 ))$temp = Array( [0] => Array ( [user_id] => 1034 [year] => 2013-2014 [term] => 1 [course_name] => 大学英语(综合)-1 [course_nature] => 必修 [credit] => 3 [grade] => 1 [course_strid] => 1 ))
$grade
if two arrays are returned as long as there is a difference $grade
Reply content:
Such as:
$grade = Array( [0] => Array ( [course_name] => 大学英语(综合)-1 [course_strid] => College English (Comprehensive)-1 [credit] => 2 [course_nature] => 必修 [grade] => 70.0 [year] => 2013-2014 [term] => 1 [user_id] => 1034 ))$temp = Array( [0] => Array ( [user_id] => 1034 [year] => 2013-2014 [term] => 1 [course_name] => 大学英语(综合)-1 [course_nature] => 必修 [credit] => 3 [grade] => 1 [course_strid] => 1 ))
$grade
if two arrays are returned as long as there is a difference $grade
Looked down, it seems that this function can meet the requirements:
Http://www.w3school.com.cn/php/func_array_diff_assoc.asp
If the landlord gives the array structure and the problem is exactly the same. Then you can use the following methods:
function compare($grade,$temp){ $compare = array_diff_assoc($grade[0],$temp[0]); if ($compare != null) { return $grade; }}
If $grade below actually contains many sub-arrays, more than $grade[0] this one, then combine the methods upstairs:
function compare($grade,$temp){ foreach($grade as $key=>$value){ $compare = array_diff_assoc($value,$temp[$key]); if ($compare != null) { return $grade; } }}
If you solve your problem, remember to adopt:)
php
foreach($grade as $key=>$item){ if($item != $temp[$key]){ return false; }}return true;
foreach simple, master to an elegant way!