Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Adi Chayot](https://secure.gravatar.com/avatar/106a1fad8c45c740c8fbfe88246c0cb5?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 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
230,688 PointsSteven Parker
230,688 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 "$").