繁体   English   中英

多维数组手动推送PHP Codeigniter

[英]Multidimensional array push manually php codeigniter

Array(    

    [0] => stdClass Object
    (
        [id] => 1
        [user_id] => 1
        [following_id] => 2
        [type] => user
        [created_on] => 2014-03-01 04:43:57
    )

   [1] => stdClass Object
    (
        [id] => 15
        [user_id] => 1
        [following_id] => 4
        [type] => user
        [created_on] => 2014-05-27 11:55:17
    )

  )

嗨,朋友们,我有一个需要手动创建下一个stdclass Object的产品数组。这些数组是通过推入值生成的。

我现在试图解决这个问题已经超过一个小时,但我无法正常工作。 我知道这应该很容易...但是无论如何-我不明白:D

我已经工作了一个小时来手动创建下一个stdclass对象。 我要这样 我如何创建这个。

有人能帮忙吗?

在此先感谢,J

阵列(

    [0] => stdClass Object
    (
        [id] => 1
        [user_id] => 1
        [following_id] => 2
        [type] => user
        [created_on] => 2014-03-01 04:43:57
    )

   [1] => stdClass Object
    (
        [id] => 15
        [user_id] => 1
        [following_id] => 4
        [type] => user
        [created_on] => 2014-05-27 11:55:17
     )
   [2] => stdClass Object
    (
        [id] => 16
        [user_id] => 1
        [following_id] => 5
        [type] => user
        [created_on] => 2014-05-27 11:55:17
    )

  )

一种实现方法是使用如下函数:

function create($id, $user_id, $following_id, $type, $created_on){
    $obj = new stdClass;
    $obj->id = $id;
    $obj->user_id = $user_id;
    $obj->following_id = $following_id;
    $obj->type = $type;
    $obj->created_on = $created_on;
    return $obj; 
}

并假设您的数组是$array ,您可以像这样向其中添加项目:

$array[] = create(16, 1, 5, 'user', '2014-05-27 11:55:17');

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM