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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -