Intercept an array that matches the condition, how to resolve

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.