Intercept an array that matches a condition
$arr = Array
(
6 = Array
(
Id=> 358
Level=> 6
)
4=> Array
(
id = 354
Level = 4
)
5 = Array
(
id = 353
Level = 5
)
)
There is an array of buttons in the order of the above to intercept the appropriate array
If the key is sorted to 6 in front as above, the key is sorted as 6,4,5 just take
$arr = Array
(
6 = Array
(
Id=> 358
Level=> 6
)
}
If the array is sorted as 5,4,6, take only 5, 62
$arr = Array
(
5 = Array
(
id = 353
Level = 5
)
6 = Array
(
Id=> 358
Level=> 6
)
)
If 4 is sorted in front, 4,5,6 is taken,
$arr = Array
(
4=> Array
(
id = 354
Level = 4
)
5 = Array
(
id = 353
Level = 5
)
6 = Array
(
Id=> 358
Level=> 6
)
)
If there are more than 4,5,6,7,8,9, how to optimize it?
------to solve the idea----------------------
Sort to 6,4,5 only 6 (can be considered to take the first or last)
Sort for 5,4,6 just take 5, 62 (this again takes Two ends)
Sort for 4,5,6 (the rules change again)
A variable rule like you can't write a program.
You don't have to give the code, the optimization is even more impossible to say
------to solve the idea----------------------
Look, the only rule you have is to take the key to the first data and go up the value
5,4,6 the first one is 5, whichever is 5 (including 5), is 5,6
4,5,6 The first one is 4, whichever is 4 (including 4), is 4,5,6
When you are in the loop, record the key value of the first data, each time to determine whether the key is greater than the first value, greater than the record
So you don't have to care about him, 7,8,9 or more data.