Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
Foreach through JSON stdClass Object array in PHP

I am fetching a JSON api in PHP, then I am attempting to iterate through the array with a foreach($obj['result'] as $c) loop. I'm specifically trying to loop through the [result] nested array, but the returned stdClass Object is not letting me do it. I have attempted to use $obj = get_object_vars($obj) but that doesn't seem to work for the $obj['result'] lower nested array. Any ideas what I do here to foreach through the $obj['result'] ?

$json = file_get_contents($rink);
$obj = array();
$obj = json_decode($json);

When I use php print_r() I get.

stdClass Object (
[status] => 1
[message] => OK
[result] => Array
    (
        [0] => stdClass Object
            (
                [blockNumber] => 10271028
                [timeStamp] => 1646413513
                [hash] => 0xab6f7d30aec4f...
            )

        [1] => stdClass Object
            (
                [blockNumber] => 10271028
                [timeStamp] => 1646413513
                [hash] => 0xab6f7d30aec4f...
            )
    )
)

Php foreach attempted loop

foreach($obj['result'] as $c) {
    echo $c['hash'] . '<br>';
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Change

foreach($obj['result'] as $c) {
    echo $c['hash'] . '<br>';
}

to

foreach($obj->result as $c) {
    echo $c->hash . '<br>';
}

Object key value is accessed with -> operator in php.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda