# Strange loop problem, won't write to array

**URL:** <https://forum.kirupa.com/t/strange-loop-problem-wont-write-to-array/269350>\
**Category:** programming\
**Created:** [August 26, 2008, 2:50pm UTC](https://forum.kirupa.com/t/strange-loop-problem-wont-write-to-array/269350 "2008-08-26T14:50:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlk](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mlk](https://forum.kirupa.com/u/mlk)\
**Post date:** [August 26, 2008, 2:50pm UTC](https://forum.kirupa.com/t/strange-loop-problem-wont-write-to-array/269350/1 "2008-08-26T14:50:14Z")

</div>

Help me there, what am I doing wrong ?

```php

<?php
$handle = opendir('../sandbox/');
$counter = 0;
$fileArray = array();
	while (false !== ($file = readdir($handle))) {
		echo $file."</br>"; //this echoes files OK
		$fileArray[$counter] = $file;
		$counter++; //I used 'count($fileArray)' as array index before
	}
	printf($fileArray); // echoes blank - it just ouputs 'Array' to the page
closedir($handle);

```
