[英]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
)
)
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. 我已经工作了一个小时来手动创建下一个stdclass对象。 I want like this.
我要这样 How do i create this.
我如何创建这个。
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
)
)
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 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.