我有两个数组,
$col = array(1,3,5,7,10...)
$data = array(1000 by 1000)
我的节目是:
$result = "";
for($i=0; $i<count($data); ++i){
for($j=0; $j<count($col); ++j){
$result .= ",".$data[$j]
}
$result .= "<br>";
}
echo $result;
问题是我如何
eliminate
inner loop
或j loop
?
由于$col
数组已经知道要选择哪个索引,我如何格式化变量的变量以便j循环可以替换为
$result = $data[1st element in $col].","$data[2nd element in $col].","...;
答案 0 :(得分:0)
它具有++$i
和$i++
,
将++ i和++ j更改为$ i ++和$ j ++
$result = "";
for($i=0; $i<count($data); $i++){
for($j=0; $j<count($col); $j++){
$result .= ",".$data[$j]
}
$result .= "<br>";
}
echo $result;