在 php 中按给定数组自定义增量


Custom Increment by given array in php

我有这样的数组

Array ( [0] => F [1] => F [2] => N [3] => )

如何使用上面的数组运行两个循环?

for ($x = 0; $x <= 2; $x++) {
    //In this loop i need the output like above 
            F-01
            F-02
    }

有一个循环,我在其中获取一些数据,例如

for ($x = 0; $x <= 1; $x++) {
//In this loop i need the output like above 
        N-01
}
为此,

您需要执行以下操作

<?php
$myarray = Array ( 'F' ,'F' ,'N' , 'l');
$j =0;
for($x = 0; $x < 2; $x++ ){
  echo $myarray[$x].'-'.$j.$x; 
echo "<br>";
}
echo "<br>";

$m=0;
for($k=2;$k<=3;$k++){
  echo $myarray[$k].'-'.$j.$m;
    echo "<br>";
}
?>

我希望这对你有帮助。