This article mainly introduces the method that PHP obtains the single-column value in the array, and analyzes the use technique of the array_column () function in PHP5.5 in combination with the instance form, the friend who needs can refer to the following
This example describes how PHP obtains a single-column value in an array. Share to everyone for your reference, as follows:
The values for the single column in the Get array in PHP are as follows:
Use the array function in PHP array_column()
: Returns the value of a single column in the array. (PHP 5.5+ applies)
Grammar:
array_column(array,column_key,index_key);
Parameters:
array : required, specified must be a multidimensional array;
Column_key : Required, the key name of the value to be returned, either an integer index of the column of the indexed array, or a string key value for the column of the associated array. This parameter can also be NULL, which is useful when the entire array is returned (with the Index_key parameter to reset the array key).
index_key : Optional. The column that is used as the index/key of the returned array.
Instance:
Remove the Last_Name column from the recordset and use the corresponding "id" column as the key value:
<?php//represents the array of possible recordsets returned by the database $ A = array (' id ' = ' = ' = ' 5698, ' first_name ' = ' Bill ', ' last_name ' = > ' Gates ',), array (' id ' = = 4767, ' first_name ' = ' Steve ', ' last_name ' = ' Jobs ',) array ( ' id ' = ' = 3809, ' first_name ' = ' Mark ', ' last_name ' = ' Zuckerberg ', '); $last _names = Array_column ($a, ' Last_Name ', ' id ');p rint_r ($last _names);? >
Output:
Array ([5698] = Gates [4767] = Jobs [3809] = Zuckerberg)