here is my code:
function my_function()
{
$states = array('schwarz', 'rot', 'blau');
foreach(range(0, 5) as $number) {
foreach ($states as $state) {
$result = "<img src=\"inventory_images/8.jpg\" onclick=\"changecolor(this)\" name=\"nummer.$number\" />";
$testPath = "transactions/Ordner$number/$state.png";
if (file_exists($testPath)) {
$result = $testPath;
}
}
break;
}
return $result;
}
$imagesPerLine = array(1=>1, 2=>2); $default = 3;
$lines = array(1, 2, 3);
$html="";
foreach ($lines as $line) {
if (!isset($imagesPerLine[$line])) {
$imagesPerLine[$line] = $default;
}
$html.= "<tr>\n";
for ($i = 1; $i <= $imagesPerLine[$line]; $i++) {
$html.=sprintf("<td>%s</td>\n", my_function());
}
$html.="</tr>\n";
}
echo $html;
and this is the output:
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
</tr>
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
</tr>
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
</tr>
now i dont know how to configure my foreach part to get the name-value = n+1.the output should be:
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.0" /></td>
</tr>
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.1" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.2" /></td>
</tr>
<tr>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.3" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.4" /></td>
<td><img src="inventory_images/8.jpg" onclick="changecolor(this)" name="nummer.5" /></td>
</tr>
firstly i thought, "break;" or "return $result;" is placed wrong, but i dont think so now. could anybody help me to change my script maybe?? thanks and greetings!!