-1

Hi I'm using this to list all files and folders from a Digital Ocean space

//List all files and folders

$myFiles = $space->ListObjects();

When I echo the result

echo '<pre>'; print_r($myFiles); echo '</pre>';

I get this

Array
(
    [0] => Array
        (
            [Key] => dam/
            [LastModified] => 1589401286
            [ETag] => "d41d8cd98f00b204e9800998ecf8427e"
            [Size] => 0
            [StorageClass] => STANDARD
            [Owner] => Array
                (
                    [DisplayName] => 7401583
                    [ID] => 7401583
                )

        )

    [1] => Array
        (
            [Key] => dam/detail-amethyst.jpg
            [LastModified] => 1589769638
            [ETag] => "4e62b16899ba8abfeffe611a8f945781"
            [Size] => 558352
            [StorageClass] => STANDARD
            [Owner] => Array
                (
                    [DisplayName] => 7401583
                    [ID] => 7401583
                )

        )

    [2] => Array
        (

And so on.

I have tried

foreach ($myFiles as $key => $val) {
    echo $key;
}

But this just gives me 01234567....

How do I get the [Key] values? I would love to create an array with just the [Key] values in. For example [dam/,dam/detail-amethyst.jpg,,,,]

Thank you.

user2238083
  • 583
  • 2
  • 9
  • 21

1 Answers1

0

What you're doing here echo $key; is printing the Array's index values.

Do it like this:

foreach ($myFiles as $key => $val) {
    echo $val['Key'];
}
gaganshera
  • 2,629
  • 1
  • 14
  • 21