Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$list = [];
for ($i = 0; $i < 10; $i++) {
$obj = new \stdClass();
$list[] = $obj;
$obj->val = $i;
}
var_dump($list);
/*
php refforloop.php
array(10) {
[0]=>
object(stdClass)#1 (1) {
["val"]=>
int(0)
}
[1]=>
object(stdClass)#2 (1) {
["val"]=>
int(1)
}
[2]=>
object(stdClass)#3 (1) {
["val"]=>
int(2)
}
[3]=>
object(stdClass)#4 (1) {
["val"]=>
int(3)
}
[4]=>
object(stdClass)#5 (1) {
["val"]=>
int(4)
}
[5]=>
object(stdClass)#6 (1) {
["val"]=>
int(5)
}
[6]=>
object(stdClass)#7 (1) {
["val"]=>
int(6)
}
[7]=>
object(stdClass)#8 (1) {
["val"]=>
int(7)
}
[8]=>
object(stdClass)#9 (1) {
["val"]=>
int(8)
}
[9]=>
object(stdClass)#10 (1) {
["val"]=>
int(9)
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment