Jump to content

Getting keys/values from POST array in an orderly fashion..


deft

Recommended Posts

I've got this javascript that results in the following being posted;

 

weight_1 = 30

cost_1 = 20

amount_1 = 32

 

weight_3 = 65

cost_3 = 23

amount_3 = 12

 

weight_7 = 43

cost_7 = 9

amount_7 = 12

 

etc.., with the numbers appended to the keys (here 1, 3, and 7) ascending but not sequential.

 

I need my PHP recieving these POST keys/values to present them like this:

 

#1

Weight: 30  Cost: 20  Amount: 30

 

#2

Weight: 65  Cost: 23  Amount: 12

 

#1

Weight: 43  Cost: 9  Amount: 12

 

 

Whats' the right way to do this?

I've been messing around with array functions but haven't quite figured out which to use..

 

 

this might be a bit crude for you but

<?php
$i = 0;
foreach($_POST as $key => $value){
if(strstr($key,"weight" != "FALSE"){echo "<br/>"; $i++; echo "#".$i."<br/>";}
//Above line adds the break between sub groups
echo $key." = ".$value."<br/>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.