I want to compare 2 arrays. But in the case of numbers, I want to compare within a specified range.
For example we go compare 3 vars : sex , color eyes and height
In the case of height, if for example people have 1,70 of height and in other array I have 1,75, I don't get results, because it only shows exact matches with that data.
I would like to show results when the other array is in the range 1,70 to 1,79
<?php
$arra_1=array("woman","blue","1,70");
$array_2=array("woman","brown","1,71");
$result=array_intersect($array_1,$array_2);
print_r($result);
?>
In these conditions with array_intersect()
, it shows me only 1 result because the only common value is "woman," but if I could compare a range of heights between 1,70 to 1,80 it would give me 2 results.
How I can compare numbers in two arrays between minimum and maximum ranges?
Rather than use
array_intersect()
which just checks for equality, you can usearray_uintersect()
which uses a function you create to compare the arrays. It should return zero if values are considered equal.This gives me this output:
(Note I had to change decimal point to
.
for it to work on my system.)