Jump to content

Array count


sandy1028

Recommended Posts

$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.

Link to comment
https://forums.phpfreaks.com/topic/218185-array-count/
Share on other sites

count will give you number of elements in array. in other words it will give you the number of array keys.

it doesn't depend upon the value of key.

 

for e.g.

$arr = array();
$arr[0] = array(1,2,3,4,5,6);
$arr[1] = array(11,22,33,44,55,66);
$arr[2] = '';

in this case count ($arr) will give you 3.

Link to comment
https://forums.phpfreaks.com/topic/218185-array-count/#findComment-1132168
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.