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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.