Created
December 18, 2021 01:01
-
-
Save zjsxwc/25e7388b777ba56b614fe7f3e9d2b126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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