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