I have passed a value from one page to another in array. I can extract first two vars by explode but I can't get the third value which is formed in an array out.

This is my array:

```
$user_rate=$_POST['user_rate'];//15000|ss|Array
list($total,$promo,$rate)=explode("|",$user_rate);

```

So I get:

```
$total=15000;
$promo=ss;
$rate=Array;

```

While Array comes from the previous page by looping the daily rate and put in an array. And I need to know what each rate is, so I wrote:

```
foreach($rate as $val){
echo "$val<br>";
}

```

But it shows nothing. How can I get this?

Updated : This is the code before the var is sent.

```
echo "
<tr>
<td align=\"right\" colspan=\"3\">Total</td>
<td align=\"right\"><label for=\"promo_3\"><input type=\"radio\" name=\"user_rate\" id=\"promo_3\" value=\"$ss_total|ss|$cost_ss\" />&nbsp;<u><b>".number_format($ss_total)."</b></u></label></td>
<td align=\"right\"><label for=\"promo_1\"><input type=\"radio\" name=\"user_rate\" id=\"promo_1\" value=\"$net_total|nc|$cost_nr\" checked/>&nbsp;<u><b>".number_format($net_total)."</b></u></label></td>
</tr>";

```

**AND THIS FORMAT OF VALUE CANNOT CHANGE BECAUSE I NEED IT FOR A LATER JAVASCRIPT EXTRACT**

While **$cost\_ss** and **$cost\_nr** are derived from database query looping.

```
while($rec=mysql_fetch_array($result)){
$cost_ss[]=$rec['rate_ss'];
$cost_nr[]=$rec['rate_nr'];
}

```
['https://Stackoverflow.com/questions/16817377', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1620626/']
this probably be a wrong `$user_rate=$_POST['user_rate'];//15000|ss|Array`

you can use `serialize / unserialize` for array
ok, many answers and no luck... i'll try it again:

you have an array $rate before you submit your form:

```
foreach($rate as $val){
   echo "$val<br>";
}

```

and you want to add $ss\_total and the string "ss" and submit it
so you need to:

```
$newarray = array('rate'=>$rate, 'type'=>'ss', 'ss_total'=>$ss_total); 
// now you have a 2-dimensional array ($newarray)

// the next step is to prepare it for form-submitting (serialize and base64_encode):
$stringvalue = base64_encode(serialize($newarray));    

// ok, now you are able to submit it as radio-field-value:
echo '<input type="radio" name="user_rate" id="promo_3" value="'.$stringvalue.'" />';

```

when the form is submitted you get a serialized and encoded string in $\_POST['user\_rate'], you can do an echo if you'd like to see how it looks.

Now you need to base64\_decode and unserialize:

```
$arr = unserialize(base64_decode($_POST['user_rate']));

```

and you have now full access to your array:

```
echo $arr['type']."<br />";

echo $arr['ss_total']."<br />";
echo $arr['rate']['index_of_rate']; // i dont know the keys of rate array...

```

access $arr in javascript:

```
echo "<script>";
echo "var jsarr = ".json_encode($arr).";\n";
echo "alert(jsarr.ss_total);\n";
echo "</script>";

```

I hope you get it now.