For an array of arrays like this:
$array = array(
0 => array (
0 => 35,
1 => 30,
2 => 39
),
1 => array (
0 => 20,
1 => 12,
2 => 5
),
...
n => array (
0 => 10,
1 => 15,
2 => 7
),
);
I need to find an entry in an array that is closer to the given parameters
find($a, $b, $c) {
}
For closer input, I mean a record that has closer values to the values specified in the input, for example. (19, 13, 3) it should return $ array [1]
The way I am doing the calculation at the moment is a loop over the entire array, storing the variable $ distance, starting at -1, and the temporary variable $ result. For each element, I calculate the distance
$dist = abs( subarray[0] - $a ) + abs ( subarray[1] - $b ) + abs( subarray[2] - $c )
and if the calculated distance is -1 or lower than the $ distance variable, which is outside the loop, I assign a new distance to varaible and save the corresponding array in the $ result variable. At the end of the loop, I get the desired value.
, : , (19, 13, false) $array [1], -
$dist = abs( subarray[0] - $a ) + abs ( subarray[1] - $b );
[2] $c.
, , , . , .
, ?