Get value from array using foreach echo and echo it outside foreach

Hello everyone, i wanted to get the value of this array using foreach and wanted to echo it outside foreach but i get 1 echo data only

Array
(
    [status] => 1
    [msg] => Array
        (
            [total_records] => 5
            [total_pages] => 1
            [page_number] => 1
            [per_page] => 100
            [return_count] => 5
            [page_result] => Array
                (
                    [0] => Array
                        (
                            [items] => 223687201
                            [is_tort] => 0
                        )

                    [1] => Array
                        (
                            [items] => 218508001
                            [stock] => 3
                        )

                    [2] => Array
                        (
                            [items] => 180097801
                            [stock] => 5
                        )

                    [3] => Array
                        (
                            [items] => 178000403
                            [stock] => 2
                        )

                    [4] => Array
                        (
                            [items] => 200052001
                            [stock] => 1
                        )

                )

        )

    [errcode] => 0
)
$gplus = $decodedInventoryArray['msg']['page_result'];

foreach($gplus as $kuda){	

       echo $kuda['items']."<br />";
}
echo $kuda['items']."<br />";

output :

223687201
218508001
180097801
178000403
178000403

Its only echo the last item, can you guys show me how to echo the item same like it echo when inside foreach loop?

I don’t get what you mean. Maybe you could provide a more minimal example and your expected output.

If i put a statement out side foreach(see arrow)

foreach($gplus as $kuda){

echo $kuda[‘items’]."
";

}
echo $kuda[‘items’]."
"; <-------

Output only : 178000403.

I wanted it to display all of the 4 item

Then use the loop instead.

But i wanted the value outside the foreach loop. Is there any code to keep the value and display it outside foreach loop?

try array_column()

Thank you. It woks better than this foreach.

Sponsor our Newsletter | Privacy Policy | Terms of Service