Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Invert varable? / Flip round.
Old 07-07-2010, 03:10 AM Invert varable? / Flip round.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,

Lets say i have:
$nums = "70,60,50,40,30,20,10";

How can i somehow invert it so it reads:
$nums = "10,20,30,40,50,60,70";

I hope someone can help, Its driving me crazy.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 07-07-2010, 05:01 AM Re: Invert varable? / Flip round.
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
So you have a comma separated string $nums, containing a list of numbers, in order, and you want to reverse it?
PHP Code:
$nums "70,60,50,40,30,20,10";
$numsArr explode(','$nums);
echo 
implode(','array_reverse($numsArr)); //10,20,30,40,50,60,70 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 07-07-2010 at 05:02 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-07-2010, 05:03 AM Re: Invert varable? / Flip round.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Thanks man.
Someone else suggested this but i didnt know hot to code it.

Thanks again.

-G
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 07-08-2010, 08:47 AM Re: Invert varable? / Flip round.
Average Talker

Posts: 22
Trades: 0
<?php
$nums = "70,60,50,40,30,20,10";
$numex = explode(',',$nums);
$cnt = count($numex);

for($i=$cnt-1;$i>-1;$i--){
$data[] = $numex[$i];
}

print_r($data);
?>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
katierosy is offline
Reply With Quote
View Public Profile Visit katierosy's homepage!
 
Reply     « Reply to Invert varable? / Flip round.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26572 seconds with 12 queries