H. G. Muller wrote on Sat, Aug 8, 2020 05:23 AM UTC:
I have some problems using sort. I have an array sqrs with 3 squares in it, and want to know what the middle square is. I had expected this could be done by
set sqrs sort #sqrs;
set middle elem 1 #sqrs;
This does not work, however. If I do printr sqrs; before and after the sort, the order of the elements is altered. But the order of the keys (0, 1, 2) is altered too, so that each element is still associated with the same key. And elem apparently retrieves the elements by key, so elem 1 #sqrs is still the same as it was without the sort.
Array
(
[1] => a1
[0] => e1
[2] => h1
)
How can I retreive the e1 from the above array, if I do not know its key, but only that it is the second element?
I have some problems using sort. I have an array sqrs with 3 squares in it, and want to know what the middle square is. I had expected this could be done by
This does not work, however. If I do printr sqrs; before and after the sort, the order of the elements is altered. But the order of the keys (0, 1, 2) is altered too, so that each element is still associated with the same key. And elem apparently retrieves the elements by key, so elem 1 #sqrs is still the same as it was without the sort.
How can I retreive the e1 from the above array, if I do not know its key, but only that it is the second element?