I am fairly new to php and I was wondering if there is a function or object all that will return the following:
Total number of variables or array elements in the $_POST array.
The Variable Names in the $_POST array.
for example if $_POST contains 3 vars such as v1, v2, v3 is there a function that I can call someing like $Count=elements($_POST);
for example if v1 is called Name and v2 is Address and v3 is phone is there something like
$VarNames = array();
$VarNames = Varlist($_POST);
where $VarNames[0] would contain Name, [2] contain Address and [3] contain phone
so therefore instead of
$Name = $_POST['Name'];
$Address = $_POST['Address'];
$Phone = $_POST['Phone'];
I can
$Name = $_POST['$VarName[0]']
$Address = $_POST['$VarName[1]'];
$Phone = $_POST['$VarName[2]'];
I am new to this so please if this sounds like a novice cause I am thx
$_POST Variable List New bee question
Moderator: General Moderators
- lord_webby
- Forum Commoner
- Posts: 44
- Joined: Wed Aug 19, 2009 9:01 am
Re: $_POST Variable List New bee question
Code: Select all
$i=0;
foreach ($_POST as $key=>$value){
echo "$key has a value of $value");
$i++;
}
echo "There are $i items";
- lord_webby
- Forum Commoner
- Posts: 44
- Joined: Wed Aug 19, 2009 9:01 am
Re: $_POST Variable List New bee question
Better:
Code: Select all
$i=0;
while ($var = each($_POST)) {
printf ("Key <b>%s</b> has the value of: <b>%s</b><br>", $var['key'], $var['value']);
$i++;
}
echo $i." results total.";
Re: $_POST Variable List New bee question
array_keys($_POST) will return array with the variable names, count($_POST) will return the count of the variables, foreach($_POST as $key => $val) {} is a loop that will give you both variable and value in the body of the loop