[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.
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.
Re: split string to array, then foreach
Thanks (again) ALL. That works perfectly.