Re: Explode, Arrays and Checkboxes
| From: | Curt Zirzow | Date: | Thu, 09 Sep 2004 04:29:54 +0000 |
| Subject: | Re: Explode, Arrays and Checkboxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196194@lists.php.net to get a copy of this message | ||
* Thus wrote Matt Winslow:
> I'm not new to PHP, but I have very little experience with arrays. I have comma separated
> values in a database, that I need to pull out, explode into an array, then check certain checkboxes
> if they exist.
>
> I have two variables:
>
> $x = "2,10,34"
> $y = "28,15,16"
>
> I need to explode them both, so that the values of $x are they keys, and the values of $y are
> the values. Is that possible?
$final = array();
$Y = explode(',', $y);
foreach(explode(',', $x) as $key => $val ) {
$final[$val] = $Y[$key];
}
var_dump($final);
>
> I have a form, with checkboxes that are named $product[1] through [40]. Next to them are
> textboxes labeled $price[1] through [40]. How would make the form, when it loads, have $product[2],
> [10], [34] checked, with $price[2], [10], and [34] equal to "28", "15", and
> "16" respecively.
>
What is the relationship between the $x,$y and $product,$price?
I'm not sure I quite grasp what your trying to do.
If I understand correctly, the situation you describe ends up not
being a one-one relationship. So a user could select 4 prices with
3 products or vice versa. Which will make things difficult to match
up products/prices.
Curt
--
The above comments may offend you. flame at will.