kworld Posted May 2, 2010 Share Posted May 2, 2010 Hey all, Im trying to reverse an xml file but the array_reverse function doesnt work. Does anyone know how i can reverse this? foreach ($xml->result->rowset->children() as $gen) Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 What does it mean to reverse a xml file? Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/#findComment-1051778 Share on other sites More sharing options...
kworld Posted May 2, 2010 Author Share Posted May 2, 2010 I want the the xml the be proccessed from old to new entries where as at the moment it proccess new to old. Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/#findComment-1051779 Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 How did you try array_reverse? Something like this should work: foreach (array_reverse($xml->result->rowset->children()) as $gen) Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/#findComment-1051786 Share on other sites More sharing options...
kworld Posted May 2, 2010 Author Share Posted May 2, 2010 Yea m8, I just keep getting this message. Warning: array_reverse() [function.array-reverse]: The argument should be an array in D:\xampplite\htdocs\lotto\test.php on line 51 Warning: Invalid argument supplied for foreach() in D:\xampplite\htdocs\lotto\test.php on line 51 Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/#findComment-1051864 Share on other sites More sharing options...
yperevoznikov Posted May 2, 2010 Share Posted May 2, 2010 Hi kworld, you are absolutely right when you said that your type of variable is not array. You think that it's array because you can iterate it's in foreach but it's just object implemented iterator interface for instance - http://php.net/manual/en/class.iterator.php. I don't know for what exactly you need reversed array but try to create yourown array by array_unshift (to reverse it) or use xpath to get some element. cheers! Quote Link to comment https://forums.phpfreaks.com/topic/200428-array-reverse/#findComment-1051865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.