php - How can I combine the following code? -
i want display 3 uls:
$one = '<ul>'; $j = 0; while($j<3){   $one .= '<li data-src="' . $myarray[0][$j] . '"></li>';   $j++; } echo $one; echo '</ul>';  $two = '<ul>'; $j = 0; while($j<3){   $two .= '<li data-src="' . $myarray[1][$j] . '"></li>';   $j++; } echo $two; echo '</ul>';  $whatever = '<ul>'; $j = 0; while($j<3){   $whatever .= '<li data-src="' . $myarray[2][$j] . '"></li>';   $j++; } echo $whatever; echo '</ul>';   how can combine above in shorter way?
like so:
for ($i = 0; $i < 3; $i++) {     echo '<ul>';     ($j = 0; $j < 3; $j++) {         echo '<li data-src="' . $myarray[$i][$j] . '"></li>';     }     echo '</ul>'; }      
Comments
Post a Comment