小编Alo*_*Jha的帖子

从存储在变量中的字符串中获取对象数据

当对象名称(类别)直接放入时,它返回正确的值,如:

 $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)

php class object

7
推荐指数
1
解决办法
63
查看次数

分解 Array 元素的每个值

我有一个像这样的数组:

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)

php arrays explode

0
推荐指数
1
解决办法
5859
查看次数

标签 统计

php ×2

arrays ×1

class ×1

explode ×1

object ×1