Array vertical slice. Is there any built-in function?

Source: Internet
Author: User
Array vertical slice. Is there any built-in function? an array with many keys, key1, key2 ,...
I want to generate a new array based on a key, which is to extract all values of a specific key to form an array.
Is there any built-in function in PHP?
This is very common. I think there should be a built-in method.
Is a vertical slice for the array key.

Is to implement the following functions

If (count ($ arr)> 0 ){
Foreach ($ arr as $ v ){
Array_push ($ newArr, $ v ['key1']);
}
}

Is there any built-in method?


Reply to discussion (solution)

Is for a key, and then take out the values under this key to form a new array

Obviously, you are referring to a two-dimensional array.
Php arrays are nested and not traditional arrays. So it's impossible to predict your operation and built-in functions
Solve this problem only by traversing it by yourself

Generally, the source of the array is database query.
The required array has been constructed when reading the query data, so there is no need to transpose the array.

To make the code more elegant and easy to read, you can use the iterator provided by SPL.
However, the efficiency may not be faster than self-writing a traversal.

Just a few lines of code are not complicated.

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.