MyBB Community Forums

Full Version: How to make $_POST['0'] to be an integer?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How can I make $_POST['0'] to be an integer? The number 0 needs to be an integer so  I can ++ it.
Just pass the integer from your form. You should have an input in your form with the name "0" as per your example POST variable above.
Try this:

$myInt = $mybb->get_input('0', MyBB::INPUT_INT);
I should explain myself more, I never do. Here goes:


$variable = 0;
$_POST[$variable]

This doesn't work.

I tried $variable = '0' and it works, but that is a string and I need it to be an integer, so in a while loop, I can increment $variable++.

How would I do that?
Try:

for ($var = 0; $var < 5; $var++) {
    $someOtherVar = $_POST[(string) $var];
}
(2015-02-10, 10:10 AM)Euan T Wrote: [ -> ]Try:


for ($var = 0; $var < 5; $var++) {
    $someOtherVar = $_POST[(string) $var];
}

Thanks! I never knew $_POST[ ' ' ] accepted just (string)$var without the ' ' inside the  [ ] .
Using "(string)" is called a cast, and casts the integer value to a string value.
Yes I know.

But I was referring $_POST['0'] because now it is $_POST[0] without the ' ' ? 

I never knew that $_POST accepts [string] as well as ['string'].
'xxx' is a string, "(string) 0" is also a string. They're the same types.
So $_POST['0'] is valid but $_POST[0] doesn't works? Weird.
Pages: 1 2