Array vertical slice. Is there any built-in function? what should I do?

Source: Internet
Author: User
Array vertical slice. Is there any built-in function? an array with many keys, key1, & nbsp; key2, & nbsp ;... I want to generate a new array based on a key & nbsp; 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. & nbsp; I think there should be a built-in method. & nbsp; it is for the 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?

------ Solution --------------------
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.
------ Solution --------------------
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.