Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Interesting behaviour with inputs and arrays.

  1. #1
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Interesting behaviour with inputs and arrays.

    Code:
    <?php
    
      echo '<pre>';
      print_r($_GET);
      echo '</pre>';
    ?>
    <form name="test" method="GET">
      <input name="input[]" type="text" />
      <input name="input[1]" type="text" />
      <input name="input[23]" type="text" />
      <input name="input[]" type="text" />
      <input type="submit" value="Test" />
    </form>
    <?php
    highlight_file(basename(__FILE__));
    ?>
    prints this array:

    Code:
    Array
    (
        [input] => Array
            (
                [0] => sdf
                [1] => dfdf
                [23] => dfdf
                [24] => fdfdf
            )
    
    )

  2. #2
    Join Date
    Dec 2005
    Posts
    41
    Rep Power
    0

    Default

    Alex,

    I know how you feel, i've been there before. But actually this kind of behavior concerning arrays is quite normal to php.

    I cite from php.net:
    If you do not specify a key for a given value, then the maximum of the integer indices is taken, and the new key will be that maximum value + 1. If you specify a key that already has a value assigned to it, that value will be overwritten.
    later.

  3. #3
    Join Date
    Dec 2005
    Posts
    41
    Rep Power
    0

  4. #4
    Join Date
    Feb 2003
    Posts
    3,175
    Rep Power
    0

    Default

    it saves php processing time. so it doesn't have to read through the whole array figureing ou the gaps in the numbers. databases do it too.

  5. #5
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    actually i was referring to the ability to specify an index to an array when collecting related data.

  6. #6
    Join Date
    Feb 2003
    Posts
    3,175
    Rep Power
    0

    Default

    yeah, php is all about ease use and flexibility.

  7. #7
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    Quote Originally Posted by owen
    yeah, php is all about ease use and flexibility.
    true, but dont you think it could do with more maturity, it has no real framework to speak of, which gives u flexibility, so much so, that u could do things very very wrongly.

  8. #8
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    or maybe php is not a language for the faint hearted but the pundits. More correctly its a very good language to ge acquanted with web programming, since its easy to learn.

    But then it should be only used again when one has mastered web programming itself, if being used for anything commercial.

  9. #9
    Join Date
    Feb 2003
    Posts
    3,175
    Rep Power
    0

    Default

    wrongly is a relative word. relative to who ever is writing it verses who is reading it. there are frameworks out there that you can tack onto it that is if you are disabled and need your hand held all the time. like a baby snatched from a mother's womb. It shouldn't be a first language though, really, it won't make you learn some basic things that a programmer should know before he/she goes off into the wild.

  10. #10
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default

    Quote Originally Posted by owen
    wrongly is a relative word. relative to who ever is writing it verses who is reading it. there are frameworks out there that you can tack onto it that is if you are disabled and need your hand held all the time. like a baby snatched from a mother's womb. It shouldn't be a first language though, really, it won't make you learn some basic things that a programmer should know before he/she goes off into the wild.
    True shouldnt be a first language, but for someone with a programming language i still think its a good intro to web programming.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •