tags:

views:

25

answers:

1

Hi,

I Want to receive items details using $_POST and list them like an invoice (exactly like paypal) So if i receive:

item_name = Flowers
item_description = Alicia Flowers Store
item_quantity = 3

item_name1 = Twilight
item_description1 = Main Library
item_quantity1 = 1

item_name2 = GTA IV
item_description2 = Rock Star
item_quantity2 = 1

I'de end up with a php array like this:

productsnames(Flowers,Twilight,GTA IV)
productsdesc(Alicia Flowers Store,Main Library,Rock Star)
productsquantities(3,1,1)

Thanks

A: 
$productsnames = array();
$productsdesc = array();
//...
foreach ($_POST as $k => $v) {
    if (preg_match('/^item_name(?:_\\d+)?$/', $k, $matches)) {
        $productsnames[] = $v;
    }
    //...
}

This assumes everything is in order. If it's not, you could use $matches[1] (and set it to 0 if inexistent) as the key for the result arrays. After that, you would probably want to sort the result arrays with ksort.

Artefacto
Thanks a bunch!!
David Smith