tags:

views:

39

answers:

1

This is what im using to loop through an array of arrays.

$csvpre = explode("###", $data);

$i = 0;
$bgc = 0;

    foreach ( $csvpre AS $key => $value){
     $info = explode("%%", $value);
     $i++;
     if($i == "1"){
      echo "<tr bgcolor=#efefef><td></td>";
       foreach ( $info as $key => $value ){ echo "<td>$value</td>"; }
      echo "</tr>";

     } else {

      if($bgc=1) { $bgcgo = "bgcolor=\"#b9b9b9\"" ;} else { $bgcgo = "bgcolor=\"#d6d6d6\""; }
      echo "<tr $bgcgo><td></td>";
       foreach ( $info as $key => $value ){ echo "<td>$value</td>"; }
      echo "</tr>";
      $bgc++;
     }  
    }

How can i add an if/elseif statement to the last foreach, so that the output changes on a given line of the array. Say i want <td>$value</td> for all unless specified, but on line 30, i want <textarea>$value</textarea>

+1  A: 

You mean like this:

<?php 
.......
echo "<tr $bgcgo><td></td>";
$j = 0;  //you need a counter
foreach ( $info as $key => $value ) { 
    $j++;  
    if ($j != 30) {
        echo "<td>$value</td>"; 
    } else {
        echo "<textarea>$value</textarea>";
    }
}
echo "</tr>";
elviejo
awesome thanks!
Patrick