逆我的意思是从以下几点:
$my_array = array(
"header" => array(
0 => "Header 1",
1 => "Header 2"
),
"paragraph" => array(
0 => "Paragraph 1",
1 => "Paragraph 2"
)
);
对此:
$my_new_array = array(
0 => array(
"header" => "Header 1",
"paragraph" => "Paragraph 1"
),
1 => array(
"header" => "Header 2",
"paragraph" => "Paragraph 2"
)
);
我知道我可以这样做:
$my_new_array = array();
foreach ( $my_array["header"] as $key => $header ){
if ( !is_array( $my_new_array[ $key ] ) ){
$my_new_array[ $key ] = array();
}
$my_new_array[ $key ]["header"] = $header;
}
foreach ( $my_array["paragraph"] as $key => $paragraph ){
$my_new_array[ $key ]["paragraph"] = $paragraph;
}
但我想知道是否有一个快速的 PHP 函数可以做到这一点或更优化的方式。我在 PHP 函数目录中找不到任何这样的函数,我想不出更优化的方法!
干杯