简体   繁体   中英

Flattening an array in PHP

I have gone through a selection of posts here on how to flatten a PHP array, but none of them have helped me to work out how to get the array down to the level I want.

The array is currently outputting like this:

array(4) { [0]=> array(1) { ["entry_id"]=> string(3) "342" } [1]=> array(1) { ["entry_id"]=> string(3) "343" } [2]=> array(1) { ["entry_id"]=> string(3) "344" } [3]=> array(1) { ["entry_id"]=> string(3) "345" } } 

I would like to have it like so:

array = (342,343,344,345)

I have managed to get it down to this:

array(4) { [0]=> string(3) "342" [1]=> string(3) "343" [2]=> string(3) "344" [3]=> string(3) "345" } 

With this code:

foreach($submissions as $a=>$b) {
            $submissions[$a] = $b['entry_id'];
        }

Thank you.

Have you tried something like

foreach($submissions as $a=>$b) {
            $submissions[] = $b['entry_id'];
        }

Because you're giving the array key=>val and the way i understand your request is you just want the values?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM