Search code examples
phparraysfilesysteminfo

i want to get my dir. info into an Multidimensional Array - PHP


I had it in an array and it worked fine now I want to insert it in a Multidimensional Array.

This is my code, not sure what I am doing or if even its poasable,

I want that the getFilename() should be assigned to a key,

Thanks for any help!

     $array_name = 1;

    $fileSystemIterator = new FilesystemIterator('work/');
    
    $someArray = array();
    foreach ($fileSystemIterator as $fileInfo){
       $array_name = array(
            'alt' => "some text",
            'link_to' => "some text",
            'img_url' => "$fileInfo->getFilename()"
        ),
$array_name++
}
        )

Solution

  • Check your double quotes in your array value for img_url.

    PS: Notice I also changed the comma to a semicolon after your array.

    (and... ident your code!)

    $fileSystemIterator = new FilesystemIterator('work/');
    
    $someArray = array();
    $array_name = array();
    foreach ($fileSystemIterator as $fileInfo) {
        $array_name[] = array(
        'alt' => "some text",
        'link_to' => "some text",
        'img_url' => $fileInfo->getFilename()
        );
    }
    print_r($array_name);