我正在使用foreach循环遍历REQUEST数组,因为我想要一个简单的方法来利用REQUEST数组的键和值。
然而,我还想要一个数字索引来记录循环运行的次数,因为我正在使用PHPExcel编写电子表格,并且我想要使用SetCellValue函数。我考虑像这样做:
foreach( $_REQUEST as $key => $value){
$prettyKeys = ucwords(preg_replace($patt_underscore," ",preg_replace($patt_CC,"_",$key)));
$prettyVals = ucwords(preg_replace($patt_underscore," ",preg_replace($patt_CC,"_",$value)));
// Replace CamelCase with Underscores, then replace the underscores with spaces and then capitalize string
// "example_badUsageOfWhatever" ==> "Example Bad Usage Of Whatever"
$myExcelSheet->getActiveSheet()->SetCellValue( "A". $built-in-foreach-loop-numerical-index ,$prettyKeys);
$myExcelSheet->getActiveSheet()->SetCellValue( "B". $built-in-foreach-loop-numerical-index ,$prettyVals);
}
我知道我可以轻松地实现类似于$c = 0
的东西,在foreach之外,然后每次运行循环时仅增加它,但有没有更简洁的方法?
for
循环。 - Tim