d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php
Add Reply New Topic New Poll
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 19 2015 11:37am
foreach($_POST as $index=>$valeur){

can someone explain to me what it means roughly?

for each elements of the array $_POST...

then I am lost
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Jun 19 2015 12:19pm
$index => $value just tells the loop to store the key of the post variable into $index and the value of the key into $value

let's say you're $_POST variable looks like so:

Code
$_POST['username'] = 'Lensherr';
$_POST['group'] = 'Members';
$_POST['gold'] = 2485.00;


and you loop through it with for each printing out the $index and $value for each iteration.

Code
foreach($_POST as $index => $value) {
print "$index = $value\n";
}


your output would be:

Code
username = Lensherr
group = Members
gold = 2485.00


This post was edited by SelfTaught on Jun 19 2015 12:20pm
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 19 2015 12:41pm
Quote (SelfTaught @ 19 Jun 2015 20:19)
$index => $value just tells the loop to store the key of the post variable into $index and the value of the key into $value

let's say you're $_POST variable looks like so:

Code
$_POST['username'] = 'Lensherr';
$_POST['group'] = 'Members';
$_POST['gold'] = 2485.00;


and you loop through it with for each printing out the $index and $value for each iteration.

Code
foreach($_POST as $index => $value) {
print "$index = $value\n";
}


your output would be:

Code
username = Lensherr
group = Members
gold = 2485.00


Thanks, that's very clear actually, I appreciate a lot your answer!
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Jun 19 2015 01:00pm
Quote (Lensherr @ Jun 19 2015 10:41am)
Thanks, that's very clear actually, I appreciate a lot your answer!


yw
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 20 2015 02:16am
Is it possible to use a foreach and still not show the name of the ' submit ' button?

I just want to know if it's possible, I don't want to know how though.

This post was edited by Lensherr on Jun 20 2015 02:16am
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Jun 20 2015 02:30am
Quote (Lensherr @ Jun 20 2015 12:16am)
Is it possible to use a foreach and still not show the name of the ' submit ' button?

I just want to know if it's possible, I don't want to know how though.



If I'm understanding your question correctly, yes it is
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 20 2015 02:35am
Quote (SelfTaught @ 20 Jun 2015 10:30)
If I'm understanding your question correctly, yes it is


yea, I am talking about the name:
Code
<input type="submit" name="valider" value="Valider" />


When using foreach it'll show all the previous
Code
name=" "
but since the input submit is a name too, it'll show the index and the value of it since that's what I am telling PHP to do when I write this echo
Code
echo '- '.$index.' : '.$valeur.'<br/>';


Well thanks, I just wanted to know if it was possible to remove the submit name and its value, now I will try to figure it out on my own.
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 22 2015 08:53am
I wondered, is there a reason anyone would use $_GET when apparently $_POST is 100 time more secure?
Member
Posts: 3,386
Joined: May 4 2013
Gold: 1,780.00
Jun 22 2015 09:20am
If you want to send someone link to this topic, how would you do it if the forum used POST and not GET?


Also it's not more secure really

This post was edited by nuvo on Jun 22 2015 09:20am
Member
Posts: 55,688
Joined: Jun 8 2006
Gold: 7.00
Jun 22 2015 01:37pm
http://www.w3schools.com/tags/ref_httpmethods.asp

After reading that, it's a lot clearer.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll