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 use 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