/    Sign up×
Community /Pin to ProfileBookmark

counting the number $_POST items sent to a page

Hi Community

is there a way that a PHP script can count the number $_post items being sent to it, if that number is knot known.

fro example if a user selects form options: option1, option3, option6 and submits the form

can the following PHP script know to only get 3 $_post items, or can i right a loop to only assign the correct number of $_post variables?

thanks
Joe

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@kingafrojoeauthorMar 01.2010 — the answer was simple

[code=php]$num = count($_POST);

echo $num;[/code]


thanks

people
Copy linkTweet thisAlerts:
@MindzaiMar 01.2010 — You also might want to look at foreach loops if you are going to be examining each value.
Copy linkTweet thisAlerts:
@kingafrojoeauthorMar 01.2010 — thanks for that!

this is now how I retrieve the $_POST data.

[code=php]$arrtime = array();
$cou=0;
foreach ($_POST as $value)
{
$arrtime[$cou] = $value;

$cou++;
}
$submit = array_pop($arrtime);[/code]
Copy linkTweet thisAlerts:
@MindzaiMar 01.2010 — You code seems a little redundant. It is effectively the same as:

[code=php]$submit = array_pop($_POST);[/code]

However even if you do need to loop, you don't need the counter variable.

[code=php]
$arrtime = array();
foreach ($_POST as $value) {
$arrtime[] = $value;
}
$submit = array_pop($arrtime);[/code]
Copy linkTweet thisAlerts:
@kingafrojoeauthorMar 01.2010 — Quite right

cheers for the help ?

[code=php]$arrtime = array();

foreach ($_POST as $value)
{
$arrtime[] = $value;
}
$submit = array_pop($arrtime);[/code]
×

Success!

Help @kingafrojoe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...