创建阵列,和一帮stdClass的对象添加到它 [英] Create array, and add a bunch of stdCLass objects to it
本文介绍了创建阵列,和一帮stdClass的对象添加到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里的基础挣扎。
我想设置一个数组,并与多个数据对象填充它,通过数组循环。
我如何添加特有多个$父数据对象,到parentarray?
当我用下面的最后一个覆盖所有其他人。由于如添加$父[]或类似的东西简单?
谢谢,
$ parentarray =阵列();
的foreach($ otherarray为$吧){
$父=新stdClass的;
$父 - >转换= $酒吧;
$父 - >负面= $常数;
}
解决方案
$ parentarray =阵列();
的foreach($ otherarray为$吧){
$父=新stdClass的;
$父 - >转换= $酒吧;
$父 - >负面= $常数;
$ parentarray [] = $父母; //还是我错了?
}
Struggling with the basics here.
I want to setup an array, and fill it with multiple data objects, by looping through an array.
How do I add multiple $parent data objects that are unique, to the parentarray?
When I use the below the last one overwrites all the others. As simple as adding $parent[] or something like that?
Thanks,
$parentarray = array();
foreach ($otherarray as $bar) {
$parent = new stdClass;
$parent->conversion = $bar;
$parent->negative = $constant;
}
解决方案
$parentarray = array();
foreach ($otherarray as $bar) {
$parent = new stdClass;
$parent->conversion = $bar;
$parent->negative = $constant;
$parentarray[] = $parent; // Or am I mistaken?
}
这篇关于创建阵列,和一帮stdClass的对象添加到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文