Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda