By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

Input being converted to integers in form array

thatos
100+
P: 105
I have the following code in an html form
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name = 'ions[1]'>
  2. <input type="text" name = 'ions[2]'>
  3. <input type="text" name = 'ions[3]'>
  4.  
The form is then posted to an php function which does the following
Expand|Select|Wrap|Line Numbers
  1. foreach($ions as $ion_id =>  $value){
  2.   echo $ion_id . " " . $value;
  3. }
  4.  
The above returns incorrect results for the following input
Expand|Select|Wrap|Line Numbers
  1. ions[1] = "";
  2. ions[2] = "12.34";
  3. ions[3] = "3";
  4.  
prints the following

1 0
2 12
3 3

Can someone please tell me how to fix this problem whereby a 0 is returned when an input field is empty and of preventing the numbers from being converted to integers. I tried to check if the value is 0 and not consider this but this results in a problem if the value typed in is 0.
Oct 18 '11 #1

✓ answered by Dormilich

I donít know where it happens, but there is definitely an integer cast somewhere before that.

what does var_dump($ions); give out?

Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
I donít know where it happens, but there is definitely an integer cast somewhere before that.

what does var_dump($ions); give out?
Oct 19 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.