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.
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
Create a query data set That is, a multidimensional array.
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.
Assign the array obtained by array_column to a variable name.
Print the obtained name array print_r
Save the array_column file and run the file in the browser. Get the array.
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!