PHP provides powerful built-in array functions that simplify working with data collections. The array_column() function helps extract values from a specific column of a multidimensional array, while array_chunk() splits a large array into smaller arrays of fixed size. These functions are especially useful in real-world scenarios such as database results processing, pagination, and data transformation.
array_column(array $array, mixed $column_key)array_chunk(array $array, int $length)
// Extract the 'name' column from a multidimensional array
<?php
$people = array(
array("id" => 1, "name" => "John", "age" => 25),
array("id" => 2, "name" => "Jane", "age" => 30),
array("id" => 3, "name" => "Bob", "age" => 35)
);
$names = array_column($people, "name");
print_r($names);
?>
The function extracts all values associated with the key name from each sub-array, returning a simple indexed array of names.
// Split an array into chunks of size 3
<?php
$numbers = array(1,2,3,4,5,6,7,8,9);
$chunks = array_chunk($numbers, 3);
print_r($chunks);
?>
The array is divided into three smaller arrays, each containing three elements. This is commonly used for pagination or batch processing.
// Conceptual visualization of array chunks
[1,2,3] | [4,5,6] | [7,8,9]
array_column().array_chunk() for memory-efficient batch operations.array_column().array_column().