Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!