将数据结构中的值提取到变量

时间:2014-05-22 08:49:25

标签: php amazon-web-services amazon-elastic-transcoder

我需要帮助从下面的数据结构中提取“持续时间”到名为var_dur的变量。

数据来自:print_r($data);

Guzzle\Service\Resource\Model Object
(
    [structure:protected] => 
    [data:protected] => Array
        (
            [Job] => Array
                (
                    [Arn] => arn:aws:elastictranscoder:us-west-2:98yufdos8u:job/fsdoiufds98u
                    [Id] => fdsu98sdufio
                    [Input] => Array
                        (
                            [AspectRatio] => auto
                            [Container] => auto
                            [FrameRate] => auto
                            [Interlaced] => auto
                            [Key] => iudyf98udsf
                            [Resolution] => auto
                        )

                    [Output] => Array
                        (
                            [AlbumArt] => 
                            [Composition] => 
                            [Duration] => 31
                            [Height] => 522
                            [Id] => 1
                            [Key] => dlsjf9ds8uf9d8sjuf9s.mp4
                            [PresetId] => sdufhy89dsfu98dsf
                            [Rotate] => 0
                            [SegmentDuration] => 
                            [Status] => Complete
                            [StatusDetail] => 
                            [ThumbnailPattern] => filename-700thumb-{resolution}-{count}
                            [Watermarks] => Array
                                (
                                )

                            [Width] => 640
                        )

                    [OutputKeyPrefix] => 
                    [Outputs] => Array
                        (
                            [0] => Array
                                (
                                    [AlbumArt] => 
                                    [Composition] => 
                                    [Duration] => 31
                                    [Height] => 522
                                    [Id] => 1
                                    [Key] => dlsjf9ds8uf9d8sjuf9s.mp4
                                    [PresetId] => duisfy98dsuf89sd
                                    [Rotate] => 0
                                    [SegmentDuration] => 
                                    [Status] => Complete
                                    [StatusDetail] => 
                                    [ThumbnailPattern] => filename-700thumb-{resolution}-{count}
                                    [Watermarks] => Array
                                        (
                                        )

                                    [Width] => 640
                                )

                        )

                    [PipelineId] => dsuf89dsuf89d
                    [Playlists] => Array
                        (
                        )

                    [Status] => Complete
                )

        )

)

2 个答案:

答案 0 :(得分:0)

做这样的事情迭代数组

function searchfor($text, $array) {
  foreach (array_expression as $key => $val)
    if($key == $text){
       return $val
    }

    if(is_array($var){
     return searchfor($text, $var);
    }
  }

  return null;
}

答案 1 :(得分:0)

试试吧

$reflect = new ReflectionClass(OBJECT);
$props   = $reflect->getProperties();
foreach ($props as $prop) {
    print $prop->getName();
    var_dump($prop->getValue());
}

关于反思课程http://www.php.net/manual/en/reflectionclass.getproperties.php

关于反射属性http://www.php.net/manual/en/class.reflectionproperty.php