moving companies : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input : Array Form Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 21 people (52%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

I'm posting to an array variable from my HTML but in the script I get a string reading "Array". Why?

May 12th, 2002 18:10
Philip Olson, Anders Feder,


All arrays will print "Array" if you print it directly, do not do that.
 For example:
  $arr = array('apple','banana','cranberry');
  print $arr;    // Array
  print $arr[0]; // apple
So treat the array from the form like any other array.  Most likely
you'll want to loop through it and do various activities with the names
and values, consider the foreach statement for this:
  foreach ($arr as $key => $value) {
      print "$key : $value\n";
  }
Will output:
  0 : apple
  1 : banana
  2 : cranberry
See:
  http://www.php.net/foreach
  http://www.php.net/array