0
<?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。

4

2 回答 2

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();
于 2012-10-18T20:58:07.360 回答
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() 函数。

除此之外,我不知道应该是什么输出。

于 2012-10-18T21:05:30.440 回答