Selective return of an array in php with Curl

Asked

Viewed 27 times

0

I have the information below in the variable $return But I would like to display only the values [code] I did

$retorno=json_decode($result, true);
foreach($retorno as $registro):
  print_r ('Código: ' . $registro['codigo'] . '<br>');
 endforeach;
Mas tenho o erro: Notice:  Undefined index: supplierProductId in 

Grateful.

Array
(
    [cadastroUnico] => Array
        (
            [0] => Array
                (
                    [cliente] => 12345678910
                    [estoque] => Array
                        (
                            [selecao] => P02
                            [transacao] => 20190711500001
                            [codigo] => 500001
                            [unidade] => UN
                            [serial] => 7898616380127
                            [quantidade] => 15
                            [data] => 2019-07-22
                            [minimo] => 1

                        )

                    [returnCode] => OK
                    [returnMessage] => Feito
                )

            [1] => Array
                (
                    [cliente] => 12345678910
                    [estoque] => Array
                        (
                            [selecao] => P02
                            [transacao] => 20190711500002
                            [codigo] => 500002
                            [unidade] => UN
                            [serial] => 7898616380356
                            [quantidade] => 3
                            [data] => 2019-07-22
                            [minimo] => 1

                        )

                   [returnCode] => OK
                    [returnMessage] => Feito
                )

1 answer

0

The codigo is inside estoque that is inside the array that is inside the cadastroUnico. You need to go "accessing" each array.

foreach($retorno['cadastroUnico'] as $k => $v) {
    print_r ('Código: ' . $v[estoque]['codigo'] . '<br>');
}

Apparently this should work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.