如何将数组设置为变量


how to set an array to a variable?

有人能帮我把下面的存储为数组吗?

我得到了的结果

Array (
    [TblCollectionReference] => Array ( 
            [content] => Array ( 
                    [0] => PBA_CA_FTL00003
                    [1] => PBA_CA_FTL00006
            )
    )
)

现在我需要15位数的代码。

我可以单独获得代码

$this->data['TblCollectionReference']['content'][0]

但是如何将其存储为数组呢?

您可以使用JSON

$toStore = json_encode($this->data['TblCollectionReference']['content']);

然后在需要的地方使用json_decode()

CakeDC有一个SerializableBehavior几乎可以自动处理。你可以在https://github.com/CakeDC/utils/blob/master/Model/Behavior/SerializableBehavior.php

我想这就是你想要的。它基本上是按照Mihai Iorga上面的建议。。。以可重复使用的方式