$array = array(
array(
"MOT"=>1,
"HAI"=>2),
array(
"MOT"=>1,
"HAI"=>2
),
array(
"MOT"=>1,
"HAI"=>2
)
);
<!DOCTYPE html>
<html>
<body>
<?php
$array = array(
array(
"MOT"=>1,
"HAI"=>2),
array(
"MOT"=>1,
"HAI"=>2
),
array(
"MOT"=>1,
"HAI"=>2
)
);
$count = count($array);
for ($x = 0; $x < $count; $x++) {
echo "<pre>";
if($x < ($count - 1)) {
if(empty(array_diff($array[$x],$array[$x+1]))) {
unset($array[$x]);
}
}
}
var_export(array_values($array));
?>
</body>
</html>
Hoặc viết dưới dạng hàm.
<!DOCTYPE html>
<html>
<body>
<?php
$array = array(
array(
"MOT"=>1,
"HAI"=>2),
array(
"MOT"=>1,
"HAI"=>2
),
array(
"MOT"=>1,
"HAI"=>2
)
);
function removevaluearraysame($array) {
$count = count($array);
for ($x = 0; $x < $count; $x++) {
echo "<pre>";
if($x < ($count - 1)) {
if(empty(array_diff($array[$x],$array[$x+1]))) {
unset($array[$x]);
}
}
}
return array_values($array);
}
$arrays = removevaluearraysame($array);
var_export($arrays);
?>
</body>
</html>