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 :
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.
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']; }}
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>
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