开发者

Looping through an array of arrays, changing output on a given line(s)

开发者 https://www.devze.com 2022-12-09 16:18 出处:网络
This is what im using to loop through an array of arrays. $csvpre = explode(\"###\", $data); $i = 0; $bgc = 0;

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 开发者_如何学Pythonwant <td>$value</td> for all unless specified, but on line 30, i want <textarea>$value</textarea>


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>";
0

精彩评论

暂无评论...
验证码 换一张
取 消