0

I need help in extracting "Duration" from the data structure below, to a variable called var_dur.

The data comes from: 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
                )

        )

)
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Nich
  • 283
  • 2
  • 12
  • 2
    Paste `print_r($data);` and not `var_dump($data);` – Hanky Panky May 22 '14 at 08:52
  • Have done as requested. – Nich May 22 '14 at 09:01
  • 1
    Please show some effort by showing your attempt at solving it. This way we can help you in a specific way. – Ronni Skansing May 22 '14 at 09:05
  • According to php's documentation, hierarchical arrays can be accessed via something like var_dump($array["parent"]["child"]["grandchild"]); I tried to access job via var_dump($array["job"]); but it did not work. – Nich May 22 '14 at 09:25
  • Also tried $array = json_decode(json_encode($data), true); but variable $array was just empty, showing Array ( ) This idea came from the second answer in http://stackoverflow.com/questions/4345554/convert-php-object-to-associative-array – Nich May 22 '14 at 09:32
  • Have resorted to extracting the duration by reading the actual video file directly with ffmpeg, rather than use the api. – Nich May 23 '14 at 02:02

2 Answers2

0

Do something like this to iterate over the Array

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;
}
Baalthasarr
  • 377
  • 1
  • 13
0

Try it

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

About reflection class http://www.php.net/manual/en/reflectionclass.getproperties.php

About reflection property http://www.php.net/manual/en/class.reflectionproperty.php

newage
  • 899
  • 7
  • 18
  • Getting: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member Guzzle\Service\Resource\Model::structure' – Nich May 22 '14 at 10:39
  • If you notice the print that I made, "Structure" is the first thing, and it says protected. What does that mean? – Nich May 22 '14 at 10:42
  • I don't know about your class. Need remove filter from getProperties `$reflect->getProperties();` – newage May 22 '14 at 10:57