Home  >  Article  >  Backend Development  >  How to use array_column() in php?

How to use array_column() in php?

青灯夜游
青灯夜游Original
2019-10-17 13:27:584443browse

array_column() is a built-in function in php, which is used to merge a column of values ​​​​with the same key in the array to form a new array. It is more suitable for the data set returned by the database query.

How to use array_column() in php?

array_column() Returns the value of a single column in the input array.

Syntax:

array_column(array,column_key,index_key);

Parameters:

●array: required. Specifies the multidimensional array (record set) to be used.

●column_key: required. The column whose value needs to be returned. Can be an integer index of a column of an index array, or a string key value of a column of an associative array. This parameter can also be NULL, in which case the entire array will be returned (very useful when used with the index_key parameter to reset the array key).

● Index_key: optional. The column used as the index/key of the returned array.

Return value: Returns an array. The value of this array is the value of a single column in the input array.

Use array_column()

First create a php file named array_column

How to use array_column() in php?

Create a query data set That is, a multidimensional array.

How to use array_column() in php?

Add the array_clumn function and add parameters. The first is the array, the second is the value column, and the third is the value column.

How to use array_column() in php?

Assign the array obtained by array_column to a variable name.

How to use array_column() in php?

Print the obtained name array print_r

How to use array_column() in php?

Save the array_column file and run the file in the browser. Get the array.

How to use array_column() in php?

For more PHP related knowledge, please visit php中文网!

The above is the detailed content of How to use array_column() in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn