我目前正在使用大量使用關聯數組的CakePHP。對於我的應用程序中的其中一個函數,如果我可以從這些數組中的某些數據創建單獨的變量,將會非常有用。例如數組可能看起來像這樣:從php函數向符號表中添加變量
Array
(
[User] => Array
(
[id] => 1
[name] => Joe Bloggs
[email] => [email protected]
)
[Post] => Array
(
[id] => 1
[title] => Hello World
)
[Profile] => Array
(
[id] => 1
[location] => London
)
)
我想創造一種可以在3陣列分裂,並給我三個新變量的函數。
我看過extract(),但它並沒有按照我想要的方式工作。我想創建三個新的變量,例如:
$user:
Array
(
[User] => Array
(
[id] => 1
[name] => Joe Bloggs
[email] => [email protected]
)
)
$post:
Array(
[Post] => Array
(
[id] => 1
[title] => Hello World
)
)
$profile:
Array(
[Profile] => Array
(
[id] => 1
[location] => London
)
)
是否有可能創造條件,能夠將這些變量添加到符號表還是我只是堅持能夠回報他們的功能?
你想要的東西,比如'$ =後數組($用戶[ '郵政']);'? – deceze
似乎有點多餘;爲什麼? – Ross