gpt4 book ai didi

php - 如何在 PHP 中创建对象列表或数组?

转载 作者:可可西里 更新时间:2023-10-31 22:10:29 24 4
gpt4 key购买 nike

我是 .net 程序员 vb 和 c#,但我似乎无法弄清楚如何在 PHP 中将我的对象放入列表或数组中。

var mylist = new List<myobject>();

mylist.add(myobject1);
mylist.add(myobject2);

我试过的。
产品是 orderitems 集合的属性:

$this->Products = getOrderItems();

public function getOrderItems()
{
$items = array();
$count = 0;

// connect to db, query.....

while($row = mysql_fetch_array($result, MYSQL_BOTH)){
$count++;
$items[$count] = ($row);
}
echo 'Count of Order Items...' . $count;

return $items;
}

我离得还近吗?

最佳答案

$items = array();

while($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$items[] = $row;
}
echo 'Count of Order Items...', count($items);

关于php - 如何在 PHP 中创建对象列表或数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/963282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com