多维数组推手动php codeigniter

时间:2020-12-15 21:37:54
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
    )

  )

Hi friends, I have an array of products that I need to create manually next stdclass Object.These array are generated by pushing value.

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

I'm trying to solve this for more than an hour now, but I don't get it to work. I know it should be easy...but anyway - I don't get it :D

我现在试图解决这个问题超过一个小时,但我没有让它发挥作用。我知道它应该很容易......但无论如何 - 我不明白:D

I have working for an hour to create manually next stdclass Object. I want like this. How do i create this.

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

Can anyone help with this?

有人能帮忙吗?

Thanks in Advance, J

先谢谢你,J

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
     )
   [2] => stdClass Object
    (
        [id] => 16
        [user_id] => 1
        [following_id] => 5
        [type] => user
        [created_on] => 2014-05-27 11:55:17
    )

  )

1 个解决方案

#1


1  

One way of doing this is to use a function like so :

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

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; 
}

And assuming your array is $array, you add items to it like this:

假设你的数组是$ array,你可以像这样添加项目:

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

Hope this helps

希望这可以帮助

#1


1  

One way of doing this is to use a function like so :

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

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; 
}

And assuming your array is $array, you add items to it like this:

假设你的数组是$ array,你可以像这样添加项目:

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

Hope this helps

希望这可以帮助