Array count


$LinksText = array();
    for ($i=0; ($i < $cnt && $i < $total); $i++ ) {
                $Text = explode ('#', $Links[$i]);
                $LinksText[]=$Text[1];
        }
$count = count($LinksText);
print_r(LinksText);
        print count($LinksText);

if($count > 0){
echo "I am not zero"
}
else {
echo "I am zero"
}


output:

Array ( [0] => [1] => ) 2
   

Please tell me why the array count is 2. and how to check if it has the values.

what are the values of $cnt and $total in


for ($i=0; ($i < $cnt && $i < $total); $i++ )

and how many elements does the array $links have in it?

$Links = $this->getLinks();
$total = count($Links);
$cnt = 5;

that’s not what I asked for.

I asked what is the value of $total, not how is the value set.

print_r($Links);

Array ( [0] => [1] => )

and $total is count of array keys.

ok, then count is 2 because you have 2 keys (elements) in your $links array and so your FOR loop is looping through 2 iterations.