如何使用foreach
创建这样的数组$data = array(
(object)array(
'oV' => 'myfirstvalue',
'oT' => 'myfirsttext',
),
(object)array(
'oV' => 'mysecondvalue',
'oT' => 'mysecondtext',
),
);
答案 0 :(得分:6)
// Create the array
$data = [];
foreach($someList as $something)
{
// Assign each value to the array as you cycle through the other collection.
$data[] = $something;
}
想到的东西
Foreach用于循环收集。如果您已经拥有包含所有这些项目的集合,那么为什么要将其重新分配给数组呢?