Returns an array that meets the conditions.
$arr = Array( 6 => Array ( id=> 358 level=> 6 ) 4=> Array ( id => 354 level => 4 ) 5 => Array ( id => 353 level => 5 ))
There is the order of such an array key to capture the appropriate array
If the key is sorted by 6 in the preceding column, for example, the key is sorted by 6 and 4 in the preceding column
$ Arr = Array
(
6 => Array
(
Id = & gt; 358
Level => 6
)
}
If the array is sorted as 5, 4, and 6, it takes only 5, 6.
$ Arr = Array
(
5 => Array
(
Id = & gt; 353
Level => 5
)
6 => Array
(
Id = & gt; 358
Level => 6
)
)
If 4 is sorted as 4, 5, and 6,
$ Arr = Array
(
4 => Array
(
Id = & gt; 354
Level => 4
)
5 => Array
(
Id = & gt; 353
Level => 5
)
6 => Array
(
Id = & gt; 358
Level => 6
)
)
If there are more than 4, 5, 6, 7, 8, 9, how can we optimize the above?
Reply to discussion (solution)
6, 4, 5, and 6 (the first or last one can be considered)
In the order of 5, 4, and 6, we can only take 5, 6 (this is to take both ends)
Order to 4, 5, and 6 (rules changed again)
A variable rule like yours cannot write programs.
You haven't provided any code, so optimization is even more difficult.
After reading this, your only rule is to take the value up based on the key of the first data.
5, 4, 6, the first is 5, get ratio 5 (including 5), is 5, 6
4, 5, 6, the first is 4, take the ratio of 4 (including 4), that is, 4, 5, 6
Then you record the key value of the first data during the loop. each time you determine whether the key is greater than the first value, it is recorded if it is greater
In this way, you don't need to worry about him, whether it's 7, 8, 9 or more data.
After reading this, your only rule is to take the value up based on the key of the first data.
5, 4, 6, the first is 5, get ratio 5 (including 5), is 5, 6
4, 5, 6, the first is 4, take the ratio of 4 (including 4), that is, 4, 5, 6
Then you record the key value of the first data during the loop. each time you determine whether the key is greater than the first value, it is recorded if it is greater
In this way, you don't need to worry about him, whether it's 7, 8, 9 or more data.
It's not disturbing. it's better than the first one. if it's OR 5, it's just. it seems there's no rule.
Consider listing all possible values.
Check whether the array_intersect_key fetch rule can be met.