Reputation: 1129
I have the following php code where it goes through a loop and push elements to an array. I wanted to count elements in that array at the end of the loop. But it is not showing anything. Can someone please help me here?
<?php
$i=0;
$uphPerOperator = [];
while($i<10){
$uphPerOperator = array_push($uphPerOperator,$i);
$i++;
}
$uphArrayCount = count($uphPerOperator);
echo $uphArrayCount; ?>
Upvotes: 0
Views: 59
Reputation: 1129
I got the code working by changing it following way
<?php
$i=0;
$uphPerOperator = [];
while($i<10){
array_push($uphPerOperator,$i);
$i++;
}
$uphArrayCount = count($uphPerOperator);
echo $uphArrayCount; ?>
Basically I changed $uphPerOperator = array_push($uphPerOperator,$i);
to array_push($uphPerOperator,$i);
and it works
Upvotes: 1