Page 1 of 1

How to print word order backwards?

Posted: Mon May 15, 2006 5:53 pm
by tvs008
Here's a string: "all cows eat grass"

How do we make this say "grass eat cows all"?

If I understand, this is not something strrev() does. So my thought was to put the string in a variable, put in into an array word by word by stripping spaces, then loop through the array backward (How do you loop through an array backward (x--) without going to -1, -2, etc?), then put the elements into a string form in a variable, then print it. That seem right?

Posted: Mon May 15, 2006 6:05 pm
by Burrito
check out krsort()

Posted: Mon May 15, 2006 7:54 pm
by tvs008
thanks,
im going to give that a try but i'd like to see it done manually as an excercise. i'll post results if i get anywhere

btw, what are the best burritos in phoenix?
i used to go to 'bertos alot ...miss that stuff

Posted: Mon May 15, 2006 8:13 pm
by John Cartwright
explode() will be useful here too

Posted: Mon May 15, 2006 11:49 pm
by Burrito
tvs008 wrote:btw, what are the best burritos in phoenix?
without question... Alfredos.

Carne Asada, enchilada style...mmmm

Posted: Mon May 15, 2006 11:55 pm
by RobertGonzalez
Hay caramba! Carne Asada, con arroz, frijoles, salsa, crema, guacamole, grande como tu pierna. Que lo quiero comer!

I know this was like way off-topic, but, seriously, you were talking carne asada. :D