你可能想看看 Hash::flatten
我认为这本食谱很好地解释了这个功能:
http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html
$arr = array(
array(
'Post' => array('id' => '1', 'title' => 'First Post'),
'Author' => array('id' => '1', 'user' => 'Kyle'),
),
array(
'Post' => array('id' => '2', 'title' => 'Second Post'),
'Author' => array('id' => '3', 'user' => 'Crystal'),
),
);
$res = Hash::flatten($arr);
/* $res now looks like:
Array (
[0.Post.id] => 1,
[0.Post.title] => First Post
[0.Author.id] => 1, [0.Author.user] => Kyle
[1.Post.id] => 2, [1.Post.title] => Second Post
[1.Author.id] => 3, [1.Author.user] => Crystal
“姐妹”函数是 Hash::expand - 它将数组恢复到其预展平状态。
当然,您总是可以编写一个循环以您喜欢的任何格式呈现数组,但这不是很“蛋糕”