PHP Foreach Loop: Push Variables into an Array
Sure, you can use the following syntax to push some variables into an array inside a PHP foreach loop:
$myArray = array(); //initialize an empty array
foreach($myVars as $var) {
array_push($myArray, $var); //push each var into the array
}
Alternatively, you can use the shorthand notation to achieve the same result:
$myArray = [];
foreach($myVars as $var) {
$myArray[] = $var; //push each var into the array
}
Hope this helps! Let me know if you have any other questions.
原文地址: https://www.cveoy.top/t/topic/mzZ5 著作权归作者所有。请勿转载和采集!