Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Adi Chayot
3,618 PointsCan someone point where i am getting wrong?
-
<?php
//add code here
$files = array();
$myfile = fopen("example", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
$line = fgets($$myfile);
array_push($files, $line);
}
echo $files;
1 Answer

Steven Parker
221,070 PointsYou're working too hard! There's a function that will give you the contents of a directory in an array all in one step.
The function's name is "scandir".
Adi Chayot
3,618 PointsAdi Chayot
3,618 PointsThank you for your answer I want to try by the long way, as i asked in this coding quastion.
Any idea why this is not working?
Steven Parker
221,070 PointsSteven Parker
221,070 PointsIf you really want "the long way", you still need to use other directory functions (like
opendir
andreaddir
) instead of file functions (likefopen
andfgets
). And testing for the end will also be done differently. There's a Secondary Example in the Teacher's Notes section of the first video in this stage.One other issue is that you have a "$$myfile" (with an extra "$").