Q
Q
Qurel2020-09-05 11:09:07
PHP
Qurel, 2020-09-05 11:09:07

How to access the property of the last element of an array without a loop in smarty?

There is an array $item.messages, how to access the .uid property of the last element of the array without a loop? I tried these options, it doesn't work:

{if $item.messages[$item.messages|@end]['uid'] == $user.id}{/if}
{if $item.messages[$item.messages|@array_keys|@array_pop]["uid"] == $user.id}{/if}

5f53479d21e27834426262.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pozdnyakov, 2020-09-05
@tutdiscoteca

Try using count and then minus one. And there will be the key of the last element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question