我的代码有什么问题???:
function my_function()
{
$states = array('schwarz', 'rot', 'blau');
$path = '';
foreach ($states as $state) {
$testPath = sprintf('transactions/Ordner/%s.png', $state);
if (file_exists($testPath)) {
$path = $testPath;
echo $path;
}
else {
$defaultPath = "inventory_images/8.jpg";
echo $defaultPath;
}
}
}
$imagesPerLine = array(1=>2, 2=>3); $default = 4;
$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;
我想,我将 my_function() 包含在“td-tag”中,但它不起作用,因为我的变量($path 和 $defaultPath)都没有被回显。我找不到我的错误,你能帮我吗?...问候