RE: [PHP] array data

From: Date: Wed, 11 Feb 2004 16:15:33 +0000
Subject: RE: [PHP] array data
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-177415@lists.php.net to get a copy of this message
It is not the correct way because $colors being an array, the HTML code for the hidden input element will look like this (once the HTML has been generated by PHP): [code] <input type="hidden" name="colors" value="Array"> [/code] What you probably want to do instead is something like this: [code] <? foreach ($colors as $color) { ?> <input type="hidden" name="colors[]" value="<?= $color ?>"> <? } ?> // close loop [/code] This will create the following HTML (for the given example)... [code] <input type="hidden" name="colors[]" value="red"> <input type="hidden" name="colors[]" value="blue"> <input type="hidden" name="colors[]" value="green"> <input type="hidden" name="colors[]" value="yellow"> [/code] ... and File2.php will do its job as desired. Shaunak > -----Original Message----- > From: Imran Asghar [mailto:imran@pak-vision.com] > Sent: Wednesday, February 11, 2004 3:17 PM > To: Php-General@Lists.Php.Net > Subject: [PHP] array data > > > Hi, > > Is not working, is it correct way???? > > File1.php > <? $colors = > array('red','blue','green','yellow'); ?> > <form action="file2.php" method="post"> > <input type="hidden" type" name="colors" > value="<?=$colors?>"> > </fomr> > > File2.php > > <? > echo $colors[0]; > echo $colors[1]; > echo $colors[2]; > echo $colors[4]; > ?> > > > > imee >

« previous php.general (#177415) next »