当对象名称(类别)直接放入时,它返回正确的值,如:
$primary = $this->dbmapper->category['primary'] ; // ( Correct Output )
Run Code Online (Sandbox Code Playgroud)
但是,当将对象名称放在名为$ dataname的变量中时,它返回空白,如:
$dataname = 'category';
$primary = $this->dbmapper->$dataname['primary'] ; ( Blank Output )
Run Code Online (Sandbox Code Playgroud)
我的构造函数变量是:
$this->dbmapper = $this->mapper();
Run Code Online (Sandbox Code Playgroud)
我的功能是:
function mapper($module='')
{
$mapper = array();
$mapper['category']['table'] = 'allcategory';
$mapper['category']['primary'] = 'categoryID';
$mapper['page']['table'] = 'allpages';
$mapper['page']['primary'] = 'pageID';
return (object) $mapper;
}
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数组:
Array
(
[2] => 2,6
[3] => 1
[4] => 14
[5] => 10
[6] => 8
)
Run Code Online (Sandbox Code Playgroud)
我想分解数组的每个元素并使用 array_map 返回一个新数组,这样我就可以避免使用循环,并创建额外的函数来回调。
O/p 应该是这样的:
Array
(
[2] => Array
(
[0] => 2
[1] => 6
)
[3] => Array
(
[0] => 1
)
[4] => Array
(
[0] => 14
)
[5] => Array
(
[0] => 10
)
[6] => Array
(
[0] => 8
)
)
Run Code Online (Sandbox Code Playgroud)