私の悪い英語でごめんなさい:(
Cakephp(or php)で「フラット配列」を「入れ子配列」に変換したい
これから :
$results = array(
array('customer' => 'John', 'hotel' => 'Sheraton', 'roomtype' => 'Single'),
array('customer' => 'John', 'hotel' => 'Sheraton', 'roomtype' => 'Double'),
array('customer' => 'John', 'hotel' => 'Sheraton', 'roomtype' => 'Triple'),
array('customer' => 'John', 'hotel' => 'Hilton', 'roomtype' => 'Single'),
array('customer' => 'Doe', 'hotel' => 'Hilton', 'roomtype' => 'Single'),
array('customer' => 'Doe', 'hotel' => 'Hilton', 'roomtype' => 'Double'),
array('customer' => 'Doe', 'hotel' => 'Sheraton', 'roomtype' => 'Single')
);
これに:
$results = array(
array(
'customer' => 'Jhon',
'children' => array(
array(
'hotel' => 'Sheraton',
'children' => array(
array('roomtype' => 'Single'),
array('roomtype' => 'Double'),
array('roomtype' => 'Triple')
)
),
array(
'hotel' => 'Hilton',
'children' => array(
array('roomtype' => 'Single')
)
),
)
),
array(
'customer' => 'Doe',
'children' => array(
array(
'hotel' => 'Hilton',
'children' => array(
array('roomtype' => 'Single'),
array('roomtype' => 'Double')
)
),
array(
'hotel' => 'Sheraton',
'children' => array(
array('roomtype' => 'Single')
)
),
)
)
);
ループを試しました(for、foreach、while)
Set::nest() cakephp ユーティリティも試しましたが、解決策がわかりません:(
これを解決する「魔法の解決策」はありますか?
ありがとう