Php 一种解析S3数据数组的方法

Php 一种解析S3数据数组的方法,php,arrays,parsing,amazon-s3,Php,Arrays,Parsing,Amazon S3,例如,如果我有这样的数组: array(34) { ["ahostel.lt/img/background.png"]=> array(4) { ["name"]=> string(29) "ahostel.lt/img/background.png" ["time"]=> int(1277819688) ["size"]=> int(36811) ["hash"]=> string(32) "

例如,如果我有这样的数组:

array(34) {
  ["ahostel.lt/img/background.png"]=>
  array(4) {
    ["name"]=>
    string(29) "ahostel.lt/img/background.png"
    ["time"]=>
    int(1277819688)
    ["size"]=>
    int(36811)
    ["hash"]=>
    string(32) "2600e98e10aba543fb2637b701dec4f3"
  }
  ["ahostel.lt/img/body-navigation-bg.png"]=>
  array(4) {
    ["name"]=>
    string(37) "ahostel.lt/img/body-navigation-bg.png"
    ["time"]=>
    int(1277819688)
    ["size"]=>
    int(409)
    ["hash"]=>
    string(32) "2e8743f24d46748c5919dfa44b51c2a5"
  }
  ["ahostel.lt/img/calendar-input.gif"]=>
  array(4) {
    ["name"]=>
    string(33) "ahostel.lt/img/calendar-input.gif"
    ["time"]=>
    int(1277819688)
    ["size"]=>
    int(630)
    ["hash"]=>
    string(32) "45d5148e7937fc75a530d7ceb73b7bc8"
  }
  ["ahostel.lt/img/facebook-icon.png"]=>
  array(4) {
    ["name"]=>
    string(32) "ahostel.lt/img/facebook-icon.png"
    ["time"]=>
    int(1277819688)
    ["size"]=>
    int(1090)
    ["hash"]=>
    string(32) "8a76e313b097f53d0f225a5db6f9ae6b"
  }
  ["ahostel.lt/img/favicon.png"]=>
  array(4) {
    ["name"]=>
    string(26) "ahostel.lt/img/favicon.png"
    ["time"]=>
    int(1277819689)
    ["size"]=>
    int(505)
    ["hash"]=>
    string(32) "daa5091eb2c059fc36b54d521e589a50"
  }
[...]
从路径ahostel.lt/img/获取所有目录和文件(尽管是在单独的数组中)的最佳解决方案是什么。我现在有很多foreach循环,这看起来并不是一个好的解决方案

$files          = array();
$directories    = array();

foreach($this->file_system as $key => $file_object_info)
{
    // make sure this is the requested path and exclude it from appearaning twice
    if(strpos($key, $path) === 0 && $key !== $path)
    {
        $relative_path  = mb_substr($key, mb_strlen($path));

        // this is a file
        if(strpos($relative_path, '/') === FALSE)
        {
            $files[$key]        = $file_object_info;
        }
        // this is a directory
        elseif(!substr($relative_path, strpos($relative_path, '/') + 1))
        {
            $directories[$key]  = $file_object_info;
        }
    }
}

我认为这是我能优化它的最远的距离。不过,情况并不像我想象的那么糟。

你能澄清一下吗?您是要提取文件名,还是要分割路径以获取目录,还是要检索实际文件?但是,我希望获得这样一个数组,其中仅包含ahostel.lt/img/path中的文件信息。