Input being converted to integers in form array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    Input being converted to integers in form array

    I have the following code in an html form
    Code:
    <input type="text" name = 'ions[1]'>
    <input type="text" name = 'ions[2]'>
    <input type="text" name = 'ions[3]'>
    The form is then posted to an php function which does the following
    Code:
    foreach($ions as $ion_id =>  $value){
      echo $ion_id . " " . $value;
    }
    The above returns incorrect results for the following input
    Code:
    ions[1] = "";
    ions[2] = "12.34";
    ions[3] = "3";
    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.
    Last edited by Niheel; Oct 18 '11, 06:22 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

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

    what does var_dump($ions) ; give out?

    Comment

    Working...