PHP

PHP Menu

PHP

array_column() Function - Definition, Syntax, Parameters, Examples

Definition

The array_column() function returns the values from a single column from the input array.

Syntax

array_column(array, column_key, index_key)

Parameters

Parameter Description
array Required. Specifies the multi-dimensional array (record-set) to use.
column_key Required. An integer key or a string key name of the column of values to return. This parameter can also be null to return complete arrays (useful together with index_key to re-index the array)
index_key Optional. The column to use as the index/keys for the returned array.

Example

<?php
$cars = array( array( 'id' => 001, 'country' => 'USA', 'car_name' => 'Ford', ), array( 'id' => 013, 'country' => 'Germany', 'car_name' => 'Volkswagen', ), array( 'id' => 253, 'country' => 'Japan', 'car_name' => 'Toyota', ) );
$countries = array_column($cars, 'country'); print_r($countries);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods