What's wrong in this loop?
I checked and i don't found errors:
$_SESSION['variable'] = 2
$prepa开发者_开发百科rado[1] = "Miguel";
$preparado[2] = "Carlos";
$segundo[1]= "Beltran";
$segundo[2] = "Sanz";
for($i = 1; $i <=$_SESSION['variable']; $i++){
$listo[$i] = $preparado1[$i] . $segundo[1];
}
for($i = ($_SESSION['variable'] + 1) ; $i <= ($_SESSION['variable'] * 2); $i++){
for($n = 1; $n <=$_SESSION['variable']; $n++){
$listo[$i] = $preparado1[$n] . $segundo[2];
}
}
for($i = 1;$i <=$_SESSION['variable'] * $_SESSION['extension']; $i++ ){
echo $final[$i] . "</br>";
}
I recibe this:
MiguelBeltran
CarlosBeltran
CarlosSanz
CarlosSanz
But I should recibe this:
MiguelBeltran
CarlosBeltran
MiguelSanz
CarlosSanz
Thanks!!
I guess you intended
$preparado[0] = "Miguel"; // rather than [1]
$preparado[1] = "Carlos";
The code you posted is not consistent with the output you presented:
There's no way you get a
Miguel
in your output as you do:$preparado[1] = "Miguel"; $preparado[1] = "Carlos";
so the only variable you assign
Miguel
to, is overwritten the next line.There is no variable
$preparado1
.
You should post the code you actually used to generate the output you got.
Given:
$_SESSION['variable'] = 2
$preparado[1] = "Miguel";
$preparado[2] = "Carlos";
$segundo[1]= "Beltran";
$segundo[2] = "Sanz";
Use:
for ($i = 1; $i <= $_SESSION['variable']; ++$i) {
for ($j = 1; $j <= $_SESSION['variable']; ++$j) {
$listo[] = $preparado[$j].$segundo[$i];
}
}
$preparado[1] = "Miguel";
$preparado[1] = "Carlos";
$segundo[1]= "Beltran";
$segundo[2] = "Sanz";
You assigned $preparado[1]
twice.
精彩评论