这里有什么PHP - 我不明白?

I have an assocaitive array with all different kind of values, but what is below will find all the array keys that end in Study and check the boolean value of it, but what I don't understand is how it works anyway care to explain a step by step explanation of it?

$study = array_filter(array_intersect_key($user, array_flip(preg_grep('/Study$/', array_keys($user)))));

if ($study) {
     ......
}

How does php sort the keys that end in Study?

And are there any better ways to do this?

Expressions with nested function calls are evaluated from the inner to the outermost parens. The order of execution is as follows:

  1. array_keys($user) - turns the array into an key list
  2. preg_grep('/Study$/', - extracts specific keys
  3. array_flip( - turns the key list back into an associative key array
  4. array_intersect_key($user, - uses that filtered associative key list to reduce the original array to the wanted subset
  5. array_filter( - removes non-true entries (NULL and false)
  6. $study = - assigns result

array_keys($user) returns the keys as values, and preg_grep('/Study$/' filters that list to return only those values that end (the $ is the end anchor) with the letters "Study", giving us a set of filtered key values.

array_flip then inverts the filtered array so that the values become keys in a new array that contains only entries with the filtered keyset.

That subset of keys is then matched with the original array keys by the array_intersect_key() function, so that only entries from the original array that have keys matching the keys in the filtered array are returned.