0

I'm trying to access information in a previously created multidimensional array. Using print_r(), I've got this info about the array(which I've spaced out myself, and may've done so oddly...):

    Array ( 
    [Video] => Array ( 
        [0] => a:3:{
            s:19:"upload_video_submit";
            s:0:"";
            s:12:"upload_video";
            s:26:"this-is-the-video-link.mp4";
            s:12:"video_length";
            s:8:"10-10-10";
            } 
    ) 
    [_edit_last] => Array ( [0] => 1 ) 
    [_edit_lock] => Array ( [0] => 1288823181 )
    [key] => Array ( 
        [0] => a:4:{
            s:4:"game";
            a:2:{
                i:0;
                s:4:"9man";
                i:1;
                s:5:"18man";
                }
            s:4:"type";
            a:1:{
                i:0;
                s:7:"Lecture";
                }
            s:5:"coach";
            a:1:{
                i:0;
                s:8:"msusyr24";
                }
            s:12:"upload-video";
            s:70:"http://localhost:8888/pocarr/wp-content/uploads/2010/09/BigCupcake.flv";
            } 
            ) 
    )

I'd like to access the arrays inside the key array, such something like echo $key_array[key][0]["type"] to get "Lecture", or echo $key_array[Video][0]["upload_video"] to get "this-is-the-videolink.mp4" ... but I'm totally baffled by the ":"s

The most I can figure is that "s" = a string, and the number is the number of characters (similarly "a"= an array).

Any ideas how to get that info out of the array?

UPDATE: I ended up using:

$new = unserialize($keys_array[Video][0]);
echo $new[upload_video];

Thanks for you help!

1
  • please, try var_dump($you_array) instead print_r($yoy_array) and post output. Commented Nov 3, 2010 at 22:50

4 Answers 4

4

Looks like some of your array values have been serialized. Check out PHP's unserialize function. Doing so will allow you to access the array elements as you describe.

For example:

print_r(unserialize($key_array[Video][0]));
Sign up to request clarification or add additional context in comments.

Comments

3

And one more thing:

if you want to format your echo code try next time with

echo "<pre>";
print_r($data);
echo "</pre>";

Comments

3

The array elements are serialized. Unserialize them, and they'll be a lot easier to access.

$videoArray = unserialize($myArray['Video'][0]);

Comments

1

Use unserialize($object);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.