<?php
function itemList(){
$items= array(
"skateboard" => array(
"name" => "Skateboard"
"type" => "drawings"
"namestripped" => "skateboard"
),
"looklocal" => array(
"name" => "Look Local"
"type" => "graphic-design"
"namestripped" => "looklocal"
),
);
reset($items);
while (list(, $value) = each($items)) {
echo '<li class="item '. $value["type"] .'">';
echo '<a class="fancybox" rel="group" href="images/portfolio/' . $value["type"] . '/'. $value["namestripped"] . '_l.jpg">';
echo '<img src="images/portfolio/' . $value["type"] . '/'. $value["namestripped"] . '.jpg" alt="' . $value . '"/>';
echo '<h3>' . $value["name"] . '</h3>'; echo '</a>';
echo '</li>';
}
}
?>
我搞砸了语法有多糟糕?当我尝试这段代码时,它不会输出任何内容,甚至不输出HTML。
答案 0 :(得分:2)
您的代码仅定义函数,但不执行它。
你会这样执行:
itemList();
编辑您的PHP代码中也有一些拼写错误。这是固定版本:
function itemList()
{
$items = array(
"skateboard" => array(
"name" => "Skateboard",
"type" => "drawings",
"namestripped" => "skateboard"
),
"looklocal" => array(
"name" => "Look Local",
"type" => "graphic-design",
"namestripped" => "looklocal"
),
);
foreach ($items AS $item)
{
echo '<li class="item '. $item["type"] .'">';
echo '<a class="fancybox" rel="group" href="images/portfolio/' . $item["type"] . '/'. $item["namestripped"] . '_l.jpg">';
echo '<img src="images/portfolio/' . $item["type"] . '/'. $item["namestripped"] . '.jpg" alt="' . $item . '"/>';
echo '<h3>' . $item["name"] . '</h3>';
echo '</a>';
echo '</li>';
}
}
itemList();
答案 1 :(得分:1)
你有一些语法错误。
$items= array(
"skateboard" => array(
"name" => "Skateboard"
"type" => "drawings"
"namestripped" => "skateboard"
),
"looklocal" => array(
"name" => "Look Local"
"type" => "graphic-design"
"namestripped" => "looklocal"
),
);;
应该是:
$items= array(
"skateboard" => array(
"name" => "Skateboard",
"type" => "drawings",
"namestripped" => "skateboard"
),
"looklocal" => array(
"name" => "Look Local",
"type" => "graphic-design",
"namestripped" => "looklocal"
)
);
你需要在其他地方调用itemList()函数。
除此之外,我不知道输出应该是什么。