What is array_ column in php?
❮ PHP Array Reference Show ExampleGet column of last names from a recordset: // An array that represents a possible record set returned from a database $last_names = array_column($a, 'last_name'); Output: Array Definition and UsageThe array_column() function returns the values from a single column in the input array. Syntaxarray_column(array, column_key, index_key) Parameter Values
Technical Details
More ExamplesExampleGet column of last names from a recordset, indexed by the "id" column: // An array that represents a possible record set returned from a database $last_names = array_column($a, 'last_name', 'id'); Output: Array ❮ PHP Array Reference Definition and UsageThe array_column() function returns the values from a single column of the input array and identified by the column_key. Optionally, you can pass index_key to index the values in the returned array by the values from the index_key column of the input array. Syntaxarray array_column( array $input , mixed $column_key [, mixed $index_key = NULL ] ) Parameters
Return ValuesThe function array_column returns an array of values representing a single column from the input array. PHP VersionThis function was first introduced in PHP Version 5.5.0. The the ability for the input parameter to be an array of objects was introduced in 7.0.0 ExampleTry out following example to get the column of first names from a recordset − 2135, 'first_name' => 'Zara', 'last_name' => 'Ali', ), array( 'id' => 3245, 'first_name' => 'Nuha', 'last_name' => 'Mac', ), array( 'id' => 5342, 'first_name' => 'Shifa', 'last_name' => 'Alam', ), array( 'id' => 5623, 'first_name' => 'Riya', 'last_name' => 'Sweet', ) ); $first_names = array_column($records, 'first_name'); print_r($first_names); ?> This will produce following result − Array ( [0] => Zara [1] => Nuha [2] => Shifa [3] => Riya ) ExampleNow let's try one more example to get the column of first names from a recordset but this time we will index recordset using id − 2135, 'first_name' => 'Zara', 'last_name' => 'Ali', ), array( 'id' => 3245, 'first_name' => 'Nuha', 'last_name' => 'Mac', ), array( 'id' => 5342, 'first_name' => 'Shifa', 'last_name' => 'Alam', ), array( 'id' => 5623, 'first_name' => 'Riya', 'last_name' => 'Sweet', ) ); $first_names = array_column($records, 'first_name', 'id'); print_r($first_names); ?> This will produce following result − Array ( [2135] => Zara [3245] => Nuha [5342] => Shifa [5623] => Riya ) php_function_reference.htm What is array_ column function in PHP?The array_column() function returns the values from a single column in the input array.
What is column array?A column matrix is a type of matrix that has only one column. The order of the column matrix is represented by m x 1, thus the rows will have single elements, arranged in a way that they represent a column of elements.
How to get a column value in PHP?YOU CAN USE MYSQLI ALTERNATIVE OF MYSQL EASY WAY
php $con=mysqli_connect("localhost","my_user","my_password","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " .
How get key of multidimensional array in PHP?Retrieving Values: We can retrieve the value of multidimensional array using the following method:. Using key: We can use key of the associative array to directly retrieve the data value. ... . Using foreach loop: We can use foreach loop to retrieve value of each key associated inside the multidimensional associative array.. |