![]() |
how to get the last child in an array and set last child to it.
dear all
In python we can write to get lastchild's last child in contents array and set lastchild to it. lastChild = lastChild.contents[-1] but in php $lastChild=end($lastChild->contents); //is it proper way to do same thing or any better way. thanks |
Well, you could do that, but those functions:
end, reset, prev, next, all modify the position of the internal pointer.For instance: Whilst we do have the last child there in our variable, the current function shows us that the internal pointer has been moved to the last element.Please take a look at my article on an internal pointers here: http://www.talkphp.com/vbarticles.ph...ents-in-arrays So, how to get the last child without modifying the internal pointer? Well, we could do the following, which would work in a similar way to Python's: php Code:
The minus one (-1) being necessary because count doesn't start at zero, whereas array keys do. |
| All times are GMT. The time now is 05:01 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0