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

230
Visualizações
How to access to specific data in variable position in object php

I am trying to return the value of an object with array in php laravel, what I am doing to access the information is the following, which works correctly, but the problem comes when the information I need changes position for example from 21 to 22 I can not access because obviously in the node in which I try to find the information does not exist

EDIT:The position of the property I am trying to access can be in different positions, that's why I need to find it by the name UUID="" and not just put an IF, besides that as the object can have several arrays I can't search for it in the controller or it adds a new array.

my object :

See example

in my blade.php:

   @foreach ($xml_objeto as $xml_objeto)
                    <tr>   
                    <td> {{ $xml_objeto[1]['Rfc'] }} </td> // works
                    <td> {{ current($xml_objeto)->UUID }} </td> // I tried but it does not work
                    <td>  {{ $xml_objeto[21]['UUID'] }} </td> // it works but when the data changes position from 21 to 22 it is no longer localized
                    <td>  {{ $xml_objeto[1]['Nombre'] }} </td>
                    </tr>
                    @endforeach 

it should be noted that it is the only data with that name UUID="" in my object. thank you very much for all the help you can give me.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

What does $xml_objeto[21]['UUID'] return when it is no longer localized?

If it comes back as an empty string, or anything else other than what you want - you could check the other index.

For example:

{{ $xml_objeto[21]['UUID'] == '' ? $xml_objeto[22]['UUID'] : $xml_objeto[21]['UUID']; }}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try using null coalescing, it will print null or whatever you want if it doesn't find that index in the array

<td>  {{ $xml_objeto[$key]['UUID'] ?? null}} </td> 

or

<td>  {{ $xml_objeto[21]['UUID'] ?? $xml_objeto[22]['UUID']}} </td> 

about 4 years ago · Juan Pablo Isaza Relatório

0

I think it's not related to the position, there is only one of your XML objects that has the UUID property right? if it is then you need to loop on the objects to extract the UUID value

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