Sure you are looking for the array_column function.

$newArray = array_column($originalArray,'0');

As said in PHP Manual, with this function you can extract, from an array of arrays, the only information you need. It is normally used with Associative arrays, but you can use a number as parameter and it will work as well.

Answer from Liz on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.array-column.php
PHP: array_column - Manual
A multi-dimensional array or an array of objects from which to pull a column of values from. If an array of objects is provided, then public properties can be directly pulled.
Discussions

Extract values from a multidimensional array using php - Stack Overflow
I have a multidimensional array like this which has been posted to a php script Array ( [users] => Array ( [0] => Array ( ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to extract/slice from a multidimensional array by its index number?
Just access the specific index like so: $subarray = $mainarray[2]; More on reddit.com
๐ŸŒ r/PHPhelp
4
3
June 17, 2021
php - how to separate and extract multidimensional array - Stack Overflow
How is it possible to separate an array depending on its multi-dimentional depth? so if I have array("string","array","string"); i want to be able to process them in a different argument so for More on stackoverflow.com
๐ŸŒ stackoverflow.com
php - extract array from multidimensional array - Stack Overflow
now here is the big problem i want to extract all user ids from $friends_inner array which name equal to my $final_result array.i am doing so but the problem is that it goes upto last index i-e 22 and than through error that index 22 and ahead is not valid offset.how can i extract the ids from ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Developer Drive
developerdrive.com โ€บ home โ€บ php arrays: array functions and multidimensional arrays
PHP Arrays: Array Functions and Multidimensional Arrays - Developer Drive
January 10, 2022 - extract($array, EXTR_PREFIX_ALL, โ€˜prefixโ€™): Adds a prefix to the string variable to differentiate between arrays that have the same keys.
Top answer
1 of 3
2

In general, you can loop through a nested array the same way as you loop through a single-level array. Example:

$myArray = array(
    'first-level-first-key' => array(
        'second-level-first-key' => 'some value',
        'second-level-second-key' => 'another value'
    ),
    'first-level-second-key' => array(
        'seond-level-another-key' => 'yet another value'
    )
);

foreach($myArray as $first_level_key => $first_level_value) {
    echo 'Key: '. $first_level_key .'<br />';
    echo 'Values: ';
    foreach($first_level_value as $second_level_key => $second_level_value) {
        echo $second_level_value .', ';
    }
    echo '<br /><br />';
}

This will print out:

Key: first-level-first-key
Values: some value, another value,

Key: first-level-second-key
Values: yet another value,

Now you know how to loop through nested arrays. Have fun!

Edit

A little bit more explanation, as an answer to tmyie's comment below: As you can see every element is an array in itself:

$myArray['first-level-first-key'] = array('second-level-first-key' => ... );

The first foreach loops through all the 'first-level' arrays (in my example the elements with key 'first-level-....'). So within that loop, the variable $first_level_value holds an array. The second foreach loops through that, second-level, array. This nesting of loops is virtually endless if you have saved yet another array in that second level element.

Compare it with having a couple of boxes in front of you. With the first loop, you say 'Open up every box in front of me'. Then for every single box you have opened, the nested loop says 'Open up every box I found in that box', and so on.

Although there is most probably something very wrong with your application design if you'd write this, the following example is completely valid:

foreach($myArray as $x) {
    foreach(y) {
        foreach(z) {
            foreach(p) {
                // etc
            }
        }
    }
}
2 of 3
1

Since $v is another array in your foreach, you need to do another foreach:

foreach($results as v) {
   foreach(timestamp => $tally) {
      // do whatever you want
   }
}

I'm not giving you a complete code and would prefer to leave that as an exercise for you, but that's how - as per your question - to extract multidimensional array

๐ŸŒ
3D Bay
clouddevs.com โ€บ home โ€บ php guides โ€บ unlocking phpโ€™s array_column() function: a practical guide
Unlocking PHP's array_column() Function: A Practical Guide
December 13, 2023 - Each element of the $students array is an associative array representing a student with their name, age, and an array of grades. The array_column() function in PHP is a versatile tool for extracting data from multidimensional arrays.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 5053303 โ€บ extract-values-from-a-multidimensional-array-using-php
Extract values from a multidimensional array using php - Stack Overflow
In php, i firstly need to obtain only the onlineid from each array item so that it can be used in a select statement (mysql) to see if the user exists. Then secondly or at the same time i need to loop through each onlineid in the array and extract the values for each key (like the comment and image in the example) so that they can be used to update a mysql database.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_arrays_multidimensional.asp
PHP Multidimensional Arrays
For a three-dimensional array you need three indices to select an element ยท To loop through a multidimensional array, use a for loop or a foreach loop.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ func_array_extract.asp
PHP extract() Function
For each element it will create a variable in the current symbol table. This function returns the number of variables extracted on success. Note: Do not use the extract() function on untrusted data, like user input from $_GET or $_FILES!
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/phphelp โ€บ how to extract/slice from a multidimensional array by its index number?
r/PHPhelp on Reddit: How to extract/slice from a multidimensional array by its index number?
June 17, 2021 -

Hi. I really some help here. I cannot figure out how to extract/slice from a multidimensional array by its index number. For example.

This is the array that I have.

Array
(
    [0] => Array
        (
            [0] => https://codeigniter.com/userguide3/helpers/array_helper.html
            [1] => blog-17.jpg
            [2] => 0
        )

    [1] => Array
        (
            [0] => https://codeigniter.com/userguide3/helpers/array_helper.html
            [1] => blog-single2.jpg
            [2] => 1
        )

    [2] => Array
        (
            [0] => https://www.koding.com/2017/05/add-update-json-file-php.html
            [1] => comment13.jpg
            [2] => 0
        )
)

What I need is to be able to get a specificy array via its index. So, if I want the array with index 2, I would get this:

Array
(
    [0] => https://www.koding.com/2017/05/add-update-json-file-php.html
    [1] => comment13.jpg
    [2] => 0
)

Thanks!

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 34249508 โ€บ how-to-separate-and-extract-multidimensional-array
php - how to separate and extract multidimensional array - Stack Overflow
Copy$temp = array('abcd',array(1,2,3),'pqr'); // example array contains string and array both. foreach($temp as $value){ if(is_array($value)){ // true if variable value is an array. echo "array"; print PHP_EOL; }else if(is_string($value)){// ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 7572130 โ€บ extract-array-from-multidimensional-array
php - extract array from multidimensional array - Stack Overflow
now here is the big problem i want to extract all user ids from $friends_inner array which name equal to my $final_result array.i am doing so but the problem is that it goes upto last index i-e 22 and than through error that index 22 and ahead is not valid offset.how can i extract the ids from ...
๐ŸŒ
GitHub
gist.github.com โ€บ 53a9b4e85cfc460eb6c22346ceb68f01
Get all values from specific key in a multidimensional array, similar to array_columns ยท GitHub
Get all values from specific key in a multidimensional array, similar to array_columns - array-value-recursive.php
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 69966364 โ€บ extract-set-of-values-from-multidimensional-array-using-an-index
php - extract set of values from multidimensional array using an index - Stack Overflow
November 14, 2021 - What I've tried: $idpresent is the array with the IDs list, $globalarray is the multidimensional array. Copyforeach($idpresent as $test){ if(in_array($test,$globalarray["id"])){ echo $globalarray["name"]; } } But I'm getting no output. Can anybody kindly help? ... Save this answer. ... Show activity on this post. Following logic might help you on your way: cycle through the whitelist ($array1) and if id is present in $array2 store the resulting record in $result array. Copy<?php $array1 = ["1","2","12","43","52"]; $array2 = [ ["id"=>"12","name"=>"Robert","surname"=>"Plant"], ["id"=>"43","name"=>"Jimmy","surname"=>"Page"], ["id"=>"8","name"=>"Mary","surname"=>"Stilton"] ]; $result = []; // result store foreach($array1 as $whitelisted) { foreach($array2 as $record) { if($record['id'] == $whitelisted) $result[] = $record; } }