1
我有一個平坦的數組,它看起來像本例:平板陣列分層多維數組
array (
0 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '1',
'@NAME' => '[CDATA[nomenclature exemple]]',
'@LEVEL' => '0',
),
),
1 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '3',
'@NAME' => '[CDATA[droit]]',
'@LEVEL' => '1',
),
),
2 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '13',
'@NAME' => '[CDATA[législation]]',
'@LEVEL' => '2',
),
),
3 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '14',
'@NAME' => '[CDATA[statuts]]',
'@LEVEL' => '3',
),
),
4 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '15',
'@NAME' => '[CDATA[projets de loi]]',
'@LEVEL' => '4',
),
),
5 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '16',
'@NAME' => '[CDATA[réglementations]]',
'@LEVEL' => '2',
),
),
6 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '17',
'@NAME' => '[CDATA[instruments statutaires]]',
'@LEVEL' => '3',
),
),
7 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '2',
'@NAME' => '[CDATA[économie]]',
'@LEVEL' => '1',
),
),
8 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '8',
'@NAME' => '[CDATA[analyse cout-avantage]]',
'@LEVEL' => '2',
),
),
9 =>
array (
'TreePad_Fields' =>
array (
'@ID' => '6',
'@NAME' => '[CDATA[analyse socio-économique]]',
'@LEVEL' => '2',
),
),
)
,我想有這樣的:
$data = array(
'[CDATA[nomenclature exemple]]' => array(
'[CDATA[droit]]' => array(
'[CDATA[législation]]' => array(
'[CDATA[statuts]]' => array(
'[CDATA[projets de loi]]'
),
),
'[CDATA[réglementations]]' => array(
'[CDATA[instruments statutaires]]'
),
),
'[CDATA[économie]]' => array(
'[CDATA[analyse cout-avantage]]',
'[CDATA[analyse socio-économique]]',
),
)
);
我不能弄清楚如何去做。我在這裏發現了其他的例子,用於將展平的數組轉換爲多維展開的數組,但沒有像這樣的自定義子類。
嗨thx爲您的評論,但仍然無法弄清楚如何做到這一點,你可以請爲我做!這真是太好了...... –