在foreach中使用数组

i have an array like this

Array
(
    [url_pic] => Array
        (
            [1001] => lvTbHafU1L2gqnmuSVMrWZzkcGJxORFs.jpg
            [1002] => Da0qf3yKRglNewH6X5n9zShLGubZVQtx.jpg
            [1003] => SGdQJ8h5CjHPkEbYpF9oglatsTfyc0nA.jpg
            [1004] => fikemigfeof330.gif
            [1005] => 7a5083ou41269s.jpg
        )

    [url_post] => Array
        (
            [1001] => http://google.com
            [1002] => http://google.com
            [1003] => http://google.com
            [1004] => http://google.com
            [1005] => http://google.com
        )

    [sort_pic] => Array
        (
            [1001] => 444
            [1002] => 777
            [1003] => 777
            [1004] => 100
            [1005] => 888
        )

)   

i want to change sort of it like this :

Array
(
    [1001] => Array
        (
            [url_pic] => lvTbHafU1L2gqnmuSVMrWZzkcGJxORFsjpg
            [url_post] => http://google.com
            [sort_pic] => 444
        )

    [1002] => Array
        (
            [url_pic] => Da0qf3yKRglNewH6X5n9zShLGubZVQtxjpg
            [url_post] => http://google.com
            [sort_pic] => 777
        )
.......

)

it works well with this code : $set_name = array();

foreach ( $result2 as $db_keys => $db_values ) {

//$set_name[] = $db_keys;

                    foreach ( $db_values as $final_key => $final_value ) {
                    $final_value_all[$final_key][$db_keys] = $final_value;
                    //$final_value_all[$final_key][$set_name] = $final_value;
                            }


}

i have no problem with upper code but i have a question about my commented lines

i write $db_keys into $set_name so $set_name output will be :

Array
(
    [0] => url_pic
    [1] => url_post
    [2] => sort_pic
)

when i want to use$set_name in $final_value_all[$final_key][$set_name] = $final_value;

i got this error : Warning: Illegal offset type

why i can't use$set_name in $final_value_all[$final_key][$set_name] = $final_value; ?

note : i know it's not necessary to use it , but i want to understanding why i can't using it

your $set_name is array if you want to use this

do it

$final_value_all[$final_key][$set_name[sizeof($set_name)-1]] = $final_value;

because

$set_name[sizeof($set_name)-1] will be equals to you $db_keys

You can't use an array as an index for another array.

Indexes have to be strings or integers.

If you want to use an array as an index, you can serialize it :

array(
    "key1"=>"value1",
    serialize(array('exemple', 'exemple2')) => "value2"
);

So you can still get back your array.

in your commented code, $set_name is an array, you can't use it as another array's index.