-2

According to the prior post I asked here. I tried hours to find out the answer. Till now there's no luck. But I getting with something with the array.

I echo the value of $_POST[user_rate] and it's = Array

So I tried to get the first array of user_rate by doing this:

echo $_POST['user_rate'][0];

And it only shows A instead of a value. I expected 2400 because the previous page I sent the array from user_rate[] (you can click the link above to see what happens back there).

Now the question is why it turns A instead of value?

Update: this is the value of user_rate after I ran the code it.

foreach($user_rate as $key=>$val){echo "$key=$val<br />";}

0=2400
1=2400
2=2400
3=2400
4=2400
5=2400
6=2400
7=2400
8=2400
9=2400
10=2400
11=2400
12=2400
13=2400

Thank you.

16
  • Are you sure the key is 0 ( numeric zero ) Commented May 29, 2013 at 17:27
  • 1
    Please state print_r($_POST). Commented May 29, 2013 at 17:27
  • php_nub_qq, yes it's zero Commented May 29, 2013 at 17:28
  • 2
    What does var_dump($_POST['user_rate']); show? Commented May 29, 2013 at 17:33
  • 2
    The value of $_POST['user_rate'] cannot both be Array and null. Take a step back, take a deep breath, and post all information available as clearly as possible. Post code, what you expect it to do, what you actually get, and a var_dump of all relevant variables in this code. We cannot answer a question by getting piecemeal information from the comment section; we need one coherent block of information. Commented May 29, 2013 at 18:18

1 Answer 1

0

The var you are echoing is a string containing 'Array'

When accessing a string as of it was an array, it will behave likean array of characters.

In this case it contains A - R -R - A - Y

Hence the first item [0] contains "A"

Since you expect a numeric in the post var I suggest you check the php script that does the Post request. Your error lays there

Sign up to request clarification or add additional context in comments.

8 Comments

Well, I tried to extract the array of $user_rate and it just fine. But after it sent across the page. The variables are gone just only "Array" left.
Show us the code you use for sending. And remember,you cant echo an entire Array to Html. If you try to echo an array object, it will be converted to the string Array
Actually to be more precise $_POST is an array but its items themselves can never be arrays because of how post requests work and how PHP manages post vars
It's something like this : 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>";. You can see the full version from the link above.
Your problem lays here : value=\"$net_total|nc|$cost_nr\". This will produce something like value="Array|nc|62547" in your Html. Just do View Source in your browser before submitting
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.