I'm working on pagination for my website, yet I'm stuck on the following piece of code. I've been messing around with it for at least an hour, and can't seem to wrap my head around what's going on with the output.
Of course the if
statement executes once.
And as expected the first echo ...
returns 1
.
However, for some reason the second echo ...
returns 0
as a float instead of <div>1</div>
as a string...
$rowCount = 5;
$pgCount = ceil($rowCount / 10);
$pgParamArray["page"] = $pgCount;
$pgArray = array("", "", "", "", "");
for ($i = 0; $i < 5; $i++) {
if ($pgParamArray["page"] - $i > 0) {
echo $pgParamArray["page"] - $i;
$pgArray[$i] = "<div>" . $pgParamArray["page"] - $i . "</div>";
echo $pgArray[$i];
}
}
I have tried setting
$pgArray
asarray()
andarray($v1, $v2, $v3, $v4, $5)
with no luck.Even though
var_dump($pgParamArray)
returns float, I tried converting $rowCount, which is initially a string from the database, to a number anyways. No dice again.echo $pgArray["0"]
also returns0
.var_dump($pgArray[0])
also returns float.var_dump($pgArray)
obviously returns array.However,
var_dump($pgArray)
returnsarray(5) { [0]=> string(7) ...
I have absolutely zero idea why $pgArray[0]
returns 0
, yet var_dump($pgArray)
returns array(5) { [0]=> string(7) ...
. That makes zero sense to me. Anybody know why $pgArray[0]
is resolving to 0
?