[php] $_POST en arrays.

Pagina: 1
Acties:

  • SchizoDuckie
  • Registratie: April 2001
  • Laatst online: 18-02-2025
Ik heb hier een formpje staan, die een aantal arrays aan php doorgeeft.

Nou wil ik hiervan de waardes uitlezen, maar tijdens het testen kwam ik er achter dat dat niet werkt?

De code die de submit afvangt ziet er nu zo uit:
PHP:
1
<?print_r($_POST);    $i = 0;    while ($i < sizeof($_POST))        {        if (is_array($_POST[$i]))            {            echo('dit is een array!<br>');            }         $i++;        }die();?>

Zoals je ziet, geeft de print_r netjes een aantal arrays terug, maar is_array niet!

Is dit een bug in php, of is het een fout in wat ik doe?
(lijkt me toch niet, ik werk al ff met php)

Stop uploading passwords to Github!


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

print_r($_POST[$i]);
wat levert dat op denk je?

Doet iets met Cloud (MS/IBM)


  • SchizoDuckie
  • Registratie: April 2001
  • Laatst online: 18-02-2025
PHP:
1
<?while ($i < sizeof($_POST))        {        print_r($_POST[$i]);         $i++;        }?>

niets! prik mij maar lek!

Stop uploading passwords to Github!


Verwijderd

zoiets?
code:
1
2
3
4
5
while(list($key, $val) = each($_POST))
{
   if(is_array($val))
    print "Array<br>";
}

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

ff een hintje
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Array
(
    [user_name] => gh
    [password1] => hh
    [password2] => fgh
    [real_name] => hghghg
    [email] => fghhg
    [email_zichtbaar] => 0
    [homepage] => http://
    [icq_uin] => gfgh
    [city] => fghh
    [gender] => Man
    [dayofbirth] => dd-mm-jjjj
    [interests] => ghg
    [submit] => Registreer
)

ik heb hier iig geen ints ;)

Doet iets met Cloud (MS/IBM)


  • SchizoDuckie
  • Registratie: April 2001
  • Laatst online: 18-02-2025
Op woensdag 22 mei 2002 16:38 schreef D2k het volgende:
ff een hintje
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Array
(
    [user_name] => gh
    [password1] => hh
    [password2] => fgh
    [real_name] => hghghg
    [email] => fghhg
    [email_zichtbaar] => 0
    [homepage] => http://
    [icq_uin] => gfgh
    [city] => fghh
    [gender] => Man
    [dayofbirth] => dd-mm-jjjj
    [interests] => ghg
    [submit] => Registreer
)

ik heb hier iig geen ints ;)
de integer reference naar een array item moet toch automagisch aangemaakt worden?

Stop uploading passwords to Github!


  • SchizoDuckie
  • Registratie: April 2001
  • Laatst online: 18-02-2025
Hmm... ok :)

Met met de each() manier werkt het wel. Wasigh, als je het mij vraagt, omdat de items die geen array zijn wel een int index krijgen.

Thx u all :)

Stop uploading passwords to Github!


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 31-08 10:19

D2k

Op woensdag 22 mei 2002 16:39 schreef Papa Eend het volgende:

[..]

de integer reference naar een array item moet toch automagisch aangemaakt worden?
code:
1
2
3
4
5
6
7
8
9
10
HTTP POST variables: $_POST
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS. 

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope. 

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS. 

$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such) 

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.

staat hier nergens iig

Doet iets met Cloud (MS/IBM)


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Papa Eend:
de integer reference naar een array item moet toch automagisch aangemaakt worden?
Waarom? Dat zou betekenen dat er niet te voorspellen is wat dit voor een array wordt:
code:
1
2
3
4
5
$array = array (
   0 => "blaat",
   1 => "blaat",
   "melp" => "baat"
);

en hiervoor
code:
1
while(list($key, $val) = each($_POST))

hebben ze de foreach uitgevonden:
code:
1
foreach ( $_POST as $key => $val )

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • SchizoDuckie
  • Registratie: April 2001
  • Laatst online: 18-02-2025
Op woensdag 22 mei 2002 16:42 schreef D2k het volgende:

[..]

[code]HTTP POST variables: $_POST
<snap>
Maar waarom werkt de while loop dan wel voor de items die géén array zijn?

Stop uploading passwords to Github!

Pagina: 1