avatar
extract column from array WordPress

• Take advantage of using array_column and handle as below:

// Sample array of data
$students = [
    ['id' => 1, 'name' => 'John', 'age' => 20],
    ['id' => 2, 'name' => 'Jane', 'age' => 22],
    ['id' => 3, 'name' => 'Bob', 'age' => 19],
    ['id' => 4, 'name' => 'Alice', 'age' => 21],
];

// Extracting just the 'name' column from the array
$names = array_column($students, 'name');
24
remove invalid elements from array in PHP Iterate over arrays in PHP with foreach loop convert array values to comma-separated string in PHP unique object in array
You need to login to do this manipulation!