More array help...

I am looking for more array help I’m sure this is an easy one but I can’t figure it out. I have an array returned from a form post that looks like this:
[php]Array
(
[position_1] => s1
[quantity_1] => q1
[position_2] => s29
[quantity_2] => q7
[position_3] => s53
[quantity_3] => q17
[position_4] => s76
[quantity_4] => q30
[position_5] =>
[quantity_5] =>
[position_6] =>
[quantity_6] =>
[position_7] =>
[quantity_7] =>
[position_8] =>
[quantity_8] =>
)[/php]
I would like to change it into an array where if position x and quantity x are both not == ‘’ the position value becomes the key of the new array and the quantity value becomes the value.

Thanks in advance.

Not sure what you are asking, but, you would just use a FOREACH clause…

Foreach($arrayname as $key=>$value){
//This allows you to “walk” down your array and look at the values and keys
//handle the if(isset(position) && isset(quantity))… etc…
}

But, first, without seeing your form, it appears you should be pulling this data as one array.
You could just code 8 IF’s and build an array…
IF($position_1!="" && $quantity!="") {$NewArray[1][1]=$position_1; $NewArray[1][2]=$quantity_1;}

There would be 8 ifs and assigns. Then the new array would be available for your use. Or, you could pull pull the data into a multidimensional new array using the $_POST array. This array is available just like any others, but, you would have to add code to check for field names.

Not sure if that is what you were asking help with… Good luck

Sponsor our Newsletter | Privacy Policy | Terms of Service