|
-
May 23rd, 2005, 10:36 AM
#1
Thread Starter
Lively Member
[resolved] split string to array, then foreach
Hello all.
I am posting a string, $_POST['hotels'], which is: "2,33,22,20,21"
I would like to split that string, at the comma, into an array, converting each to a number, then doing a foreach.
I was thinking:
Code:
$hotels = split(',',$_POST['hotels']);
foreach ($hotels as $x) {
//convert $x to a number
//do something with $x
}
But I'm not doing it right.
Any help is greatly appreciated.
Many thanks.
Last edited by solitario; May 27th, 2005 at 02:52 PM.
-
May 23rd, 2005, 10:56 AM
#2
Fanatic Member
Re: split string to array, then foreach
well, i am no wiz at php, but cant strings be used as a number value as well? i know CGI it is like that.
so couldnt you do a calculation like this:
Code:
$hotels = split(',',$_POST['hotels']);
echo $hotels."*5=";
$a = $hotels[0] * 4;
echo $a;
that should take the first array of $hotels and multiply it by 4 then echo the result.
-
May 23rd, 2005, 01:24 PM
#3
Thread Starter
Lively Member
Re: split string to array, then foreach
Thanks (again) ALL. That works perfectly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|