0

I have php Array. I need get only product Id's in foreach. How i can make this? Just need some list of product ID's. How i can parse array in foreach? I tried like this ($numenclatureS['terminalGroupStopLists'][0]['items'] as $product)

Array
    (
        [correlationId] => 3b1ba055-c216-49de-9f85-209f68adf55b
        [terminalGroupStopLists] => Array
            (
                [0] => Array
                    (
                        [organizationId] => 7e3e9763-67a8-43ec-a663 9daf00f98945
                        [items] => Array
                            (
                                [0] => Array
                                    (
                                        [terminalGroupId] => 743a13f7-c0b1-41b6-b45a-2be970abff19
                                        [items] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [balance] => 0
                                                        [productId] => 137e576d-ac4e-4d60-8da2-9048e56c063a
                                                    )
    
                                                [1] => Array
                                                    (
                                                        [balance] => 0
                                                        [productId] => 06ea7ef2-8067-4b0b-9376-d1439a70f110
                                                    )
    
                                                [2] => Array
                                                    (
                                                        [balance] => -8
                                                        [productId] => 07040e16-7ae9-4f9e-a7c8-182ab89453f0
                                                    )
    
                                                [3] => Array
                                                    (
                                                        [balance] => 0
                                                        [productId] => e423da4a-b12e-4d93-a557-7cace4f565b9
                                                    )

    
                                            )
    
                                    )
    
                            )
    
                    )
    
            )
    
    )
Sergei
  • 11
  • 3
  • 1
    https://stackoverflow.com/q/46275040/2943403, https://stackoverflow.com/a/10152943/2943403 – mickmackusa Feb 02 '21 at 03:46
  • 1
    Does this answer your question? [php multidimensional array get values](https://stackoverflow.com/questions/10152920/php-multidimensional-array-get-values) – Mohd Alomar Feb 02 '21 at 06:06

1 Answers1

0

It's working if i do this

<?php 
$zzz = $numenclatureS['terminalGroupStopLists'];
$zzz1 = $zzz[0]['items'][0];
$zzz2 = $zzz1['items'];
?>


<?php foreach ($zzz2 as $product): ?>
<?php echo $product['productId']; ?>
<br />
<?php endforeach; ?>

maybe there is an easier way?

Sergei
  • 11
  • 3
  • 1
    If there are only ever one element `[0]` to TerminalGroupStopLists and items, you can probably use `array_column($numenclatureS['terminalGroupStopLists'][0]['items'][0], 'productId')` https://www.php.net/manual/en/function.array-column.php – Michael Berkowski Feb 02 '21 at 02:52