0
爲什麼這會工作?我認爲變量只能在範圍內可見...或者是範圍方法?變量作用域方法{foreach {if(){variable} else {}}}
1)理想情況下:$變量名將被定義爲foreach的第一步...但是如何?
2)爲什麼在整個foreach塊中的if子句中定義了$變量?
3)PHPStorm我得到一個編譯錯誤,但代碼工作...
ArrayObject的__construct:
// read JSON
foreach ($jsonIterator as $key => $val) {
if ($jsonIterator->getDepth()===0){
$variable = new Preguntas_Educacion_V1($key);
$this->offsetSet($variable->getColumn(),$variable);
} else if ($jsonIterator->getDepth()===1){
//Reflection!!! call setter dynamically by Val
$function="set".ucfirst($key);
$variable->$function($val);
} else if ($jsonIterator->getDepth()===2){
//Respuestas array
}
$counter++;
}
如果它在先前迭代被設定,它仍然在下次迭代(其直到腳本除非'未設置(的端部限定的定義)'或設置爲等於爲空),即使滿足不同的條件。如果你想閱讀關於範圍,[這是一個很好的線程](http://stackoverflow.com/q/16959576/4535200)。 – Qirel