RE: [PHP] Forms and Arrays

From: Mike Ford (M.Ford_at_lmu.ac.uk)
Date: 11/28/03


To: 'Dave Carrera' <dave@ephgroup.com>, php-general@lists.php.net
Date: Fri, 28 Nov 2003 14:49:37 -0000

On 28 November 2003 14:36, Dave Carrera wrote:

> Hi List,
>
> I have a dynamically generated form with inputs with names that
> create arrays i.e.:
>
> <input name="fname[]">
> <input name="flab[]">
> <input name="fplc[]">
>
> The extra bits for the inputs are omitted deliberately for
> this question but
> exists in the form i.e.: size, value, type.
>
> And these are repeated as many time as required.
>
> Thus they are generating arrays called:
>
> Fname0
> Flab0
> Fplc0
> Fname1
> Flab1
> Fplc1
> Fname2
> Flab2
> Fplc2

Sorry to be pedantic, but, no, they are generating arrays called fname,
flab, and fplc. The elements of these arrays are fname[0], fname[1],
fname[2]..., flab[0], flab[1]... etc.

> And so on as per the num of dynamically generated input lines
> for the form.
 
> My question is

This describes one way of handling the arrays:

> how can I treat each array separately and then
> move on to the
> next until end ?
>
> SO the output would be :

... but this illustrates exactly the opposite way of treating them:
 
> fname0 = value flab0 = value fplc0 = value
> fname1 = value flab1 = value fplc1 = value
> fname2 = value flab2 = value fplc2 = value

So which is it you want? Presumably, your example output is correct and the
description is wrong, and what you really want to do is address the first
element of each array, then the second element of each array, and so on. In
which case, you've pretty much described how to do it in your example
output, and your only remaining problem is how to find out how long the
arrays are -- for which I recommend you take a look at
http://www.php.net/count.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211



Relevant Pages

  • RE: [PHP] Is there a php built-in function to determine the numbe r of dimensions of the array?
    ... All PHP arrays are 1-dimensional. ... nesting, then, no, I don't believe there's a built-in function for this. ... Learning Support Services, Learning & Information Services, ...
    (php.general)
  • RE: [PHP] Major wierdness - ack!
    ... > I have put some error trapping code in my site with the ... Mike Ford, Electronic Information Services Adviser, ... Learning Support Services, Learning & Information Services, ...
    (php.general)
  • RE: [PHP] eregi filter stopping valid email address, part two
    ... No. You've only allowed for hyphens in the first element after the @ sign ... Mike Ford, Electronic Information Services Adviser, ... Learning Support Services, Learning & Information Services, ...
    (php.general)
  • RE: [PHP] sorting
    ... then all the comparisons are string-ti-string, so there are no type conversions involved, so your sort proceeds exactly how you expect. ... Mike Ford, Electronic Information Services Adviser, ... Learning Support Services, Learning & Information Services, ...
    (php.general)
  • RE: [PHP] stepping through alphabet
    ... Jay Blanchard contributed these pearls of wisdom: ... Mike Ford, Electronic Information Services Adviser, ... Learning Support Services, Learning & Information Services, ...
    (php.general)