Jump to content

count function


meltingpoint

Recommended Posts

the file (db_file.txt)contains four things:

monkey

apple

orange

pear

 

when I use    $XX = file("db_file.txt", "r");

and then print_r($XX);

it returns- Array([0]=>monkey[1]=>apple[2]=>orange[3]=>pear[4]=> )

using $size = count($XX);

it gives - 5

 

So why is it giving a 5th element to the file?

 

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

Because there is an erroneous new line character after the last line... so it reads the blank line as well... that is why the 4th index is blank.

 

Put the cursor on the line below the last item and backspace it up so the cursor is behind the last piece of data and it should correct it.

Link to comment
https://forums.phpfreaks.com/topic/163649-count-function/#findComment-863468
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.