Jump to content

[SOLVED] array order...


redarrow

Recommended Posts

The arrays $a $b $c should be in there own order but there not...

 

result

Memeber A: a1

 

Memeber B: b1

 

Memeber C: c1

 

Memeber A: a2

 

Memeber B: b2

 

Memeber C: c2

 

Memeber A: a3

 

Memeber B: b3

 

Memeber C: c3

 

Memeber A: a4

 

Memeber B: b4

 

Memeber C: c4

 

can u tell me why pease..........

 

<?php

if(isset($_POST['submit'])){


//PRINT_R($_POST['a']);
    //PRINT_R($_POST['b']);
    //PRINT_R($_POST['c']);

$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];

  for($i=0; $i<count($a); $i++, $b++, $c++){ 

    echo " Memeber A: ".$a[$i]." <br><br> Memeber B: ".$b[$i]."  <br><br> Memeber C: ".$c[$i]." <br><br>";
    
}
}

echo"<form action='forms.php' method='POST'>";

  $pilot_row1=array("a1","a2","a3","a4");
  $pilot_row2=array("b1","b2","b3","b4");
  $pilot_row3=array("c1","c2","c3","c4");
  
  
for($i=0; $i<count($pilot_row1); $i++, $pilot_row2++,$pilot_row3++){ 

echo"
<input type='hidden' name='a[]' value='$pilot_row1[$i]'><br>
<input type='hidden' name='b[]' value='$pilot_row2[$i]'><br>
<input type='hidden' name='c[]' value='$pilot_row3[$i]'><br>
";
}

echo"<input type='submit' name='submit' value='Remove'></form>";
?>

Link to comment
https://forums.phpfreaks.com/topic/129190-solved-array-order/
Share on other sites

as u can see the array order is correct tried every posable loop no joy.......

Array ( [0] => a1 [1] => a2 [2] => a3 [3] => a4 ) 

Array ( [0] => b1 [1] => b2 [2] => b3 [3] => b4 ) 

Array ( [0] => c1 [1] => c2 [2] => c3 [3] => c4 ) 

 

what it should look like......

Memeber A:
a1
a2
a3
a4

Memeber B:
b1
b2
b3
b4

Memeber C:
c1
c2
c3
c4

 

 

but preduced manualy how do u get the same results using a loop.......

<?php

if(isset($_POST['submit'])){


//PRINT_R($_POST['a']);
    //PRINT_R($_POST['b']);
    //PRINT_R($_POST['c']);

$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];

   
echo "<br> Memeber A: <br> $a[0] <br> $a[1] <br> $a[2] <br> $a[3]<br><br> Memeber B: <br> $b[0] <br> $b[1] <br> $b[2] <br> $b[3]  <br><br> Memeber C: <br> $c[0] <br> $c[1] <br> $c[2] <br> $c[3]<br><br>";
    

}
?>

Link to comment
https://forums.phpfreaks.com/topic/129190-solved-array-order/#findComment-669795
Share on other sites

solved implode <<<<<<<<<<<,

 

Memeber A: a1 a2 a3 a4

 

Memeber B: b1 b2 b3 b4

 

Memeber C: c1 c2 c3 c4

 

<?php

if(isset($_POST['submit'])){
   
   
   //PRINT_R($_POST['a']);
    //PRINT_R($_POST['b']);
    //PRINT_R($_POST['c']);
   
   $a=$_POST['a'];
   $b=$_POST['b'];
   $c=$_POST['c'];
    
   $a=implode(' ',$a);
   $b=implode(' ',$b);
   $c=implode(' ',$c);
   
    echo " Memeber A: $a <br><br> Memeber B: $b  <br><br> Memeber C: $c <br><br>";
    
    exit;
}


echo"<form action='forms.php' method='POST'>";

  $pilot_row1=array("a1","a2","a3","a4");
  $pilot_row2=array("b1","b2","b3","b4");
  $pilot_row3=array("c1","c2","c3","c4");
  
  
for($i=0; $i<count($pilot_row1); $i++){ 

echo"
<input type='hidden' name='a[]' value='$pilot_row1[$i]'>
";
}

for($i=0; $i<count($pilot_row2); $i++){ 
echo"
<input type='hidden' name='b[]' value='$pilot_row2[$i]'>
";
}

for($i=0; $i<count($pilot_row3); $i++){ 
echo"
<input type='hidden' name='c[]' value='$pilot_row3[$i]'>
";
}

echo"<input type='submit' name='submit' value='Remove'></form>";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/129190-solved-array-order/#findComment-669800
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.