CakePHP函数将点阵数转换为多维数

nic*_*ckf 2 arrays cakephp multidimensional-array

在CakePHP中,似乎很多函数可以将它们的参数作为嵌套的多维数组或虚线字符串:

$this->MyModel->contain(array(
    'Something', 'Something.Else', 'Something.Else.Entirely'
));
$this->MyModel->contain(array(
    'Something' => array(
        'Else' => 'Entirely'
    )
));
Run Code Online (Sandbox Code Playgroud)

因此,我认为核心中必须有一个函数可以从虚线切换到嵌套的关联,但我找不到它的生命.有任何想法吗?

nic*_*ckf 8

我实际上已经找到了自己的方法来利用内置的Set函数.

鉴于:

$input = array (
    'Post.id' => 1,
    'Post.title' => 'Some post title.',
    'Post.Tag.0.id' => 4,
    'Post.Tag.0.name' => 'cakephp',
    'Post.Tag.1.id' => 7,
    'Post.Tag.1.name' => 'mysql',
);
Run Code Online (Sandbox Code Playgroud)

此代码将它放入嵌套的关联数组中.

$output = array();
foreach ($input as $key => $value) {
    $output = Set::insert($output, $key, $value);
}
Run Code Online (Sandbox Code Playgroud)

这是文档 Set::insert()