I have been following a tutorial on readdir(), is_dir() etc involved in setting up a small image gallery based on folders and files on my FTP. I was wondering what the $directorys[] = $file; part does specifically?
while( $file= readdir( $dir_handle ) )
{
if( is_dir( $file ) ){
$directorys[] = $file;
}else{
$files[] = $file;
}
}
It pushes an item to the array, instead of
array_push
, it would only push one item to the array.Using
array_push
and$array[] = $item
works the same, but it's not ideal to usearray_push
as it's suitable for pushing multiple items in the array.Example:
After doing this
$array[] = 'This works!';
orarray_push($array, 'This works!')
it will appear as this:Also you can push arrays into an array, like so: