I'm trying to build an events page for my band's website using PHP to list our upcoming gigs (I'm still quite new to server side script) And I keep getting the above error displaying on the page in browser. I'm sure there's something simple I'm missing / doing wrong but I can't seem to figure out what it is (I'm struggling to find relevant info online too)

我正在尝试使用PHP为我的乐队网站建立一个活动页面,列出我们即将到来的演出(我对服务器端脚本还很新)我一直在浏览器页面上显示上面的错误。我确信有一些简单的东西我错过了/做错了但我似乎无法弄清楚它是什么(我也在努力在网上找到相关信息)

Here is my code on the html / php page

这是我在html / php页面上的代码

<?php
$body_id = 'gigs'
?>

<?php include($_SERVER['DOCUMENT_ROOT'].'/fragments/html.html'); ?>

<div class="content-left">

    <?php
    include($_SERVER['DOCUMENT_ROOT'].'/php/arr_gigs.php');

    foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {

        echo '<span class="top">\n\t';
        if ($ticket_link = true){
            echo '<a href="$ticket_link" onClick="return false;"> BOOK TICKETS </a>\n';
        };
        echo '</span>\n\n';                         
        echo '<span class="bottom">\n\t';
        echo '<a href="$event_link" class="gig-tag" onClick="return false;">\n\t\t';
        echo '<span class="when">$day \/ $month - $location</span>\n\t\t';
        echo '<span class="where">$description</span>\n\t';
        echo '</a>\n';
        echo '</span>\n';
    };
?>

</div>

And here is php/arr_gigs.php where I hope to put in all the gig details, date, location, links etc.

这里是php / arr_gigs.php,我希望在这里放入所有的演出细节,日期,地点,链接等。

<?php

$gig = [
[28,12,2013,
'The Firebug - Leicester', 
'with more awesome bands',
'www.facebook.com',
'www.seetickets.com'],

[19,04,2014,
'Pi Bar - Leicester', 
'(acts tbc)',
'www.facebook.com',
''],
];

?>

As far as I know I'm running the latest version of PHP (5.3 or similar) If there's any help or advice someone could give me I'd be really grateful :) Or if you think there's a better way I could achieve the desired effect

据我所知,我正在运行最新版本的PHP(5.3或类似版本)如果有任何帮助或建议,有人可以给我,我真的很感激:)或者如果你认为有更好的方法我可以实现所需影响

1 个解决方案

#1


1

The following line of code is not valid in PHP versions prior to 5.5 (this means you are not using PHP 5.5):

以下代码行在5.5之前的PHP版本中无效(这意味着您不使用PHP 5.5):

foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {

If you wish to get all of those values either use the array syntax to access them:

如果您希望获得所有这些值,请使用数组语法来访问它们:

foreach ($gig as $giginfo) {
    echo $giginfo['day'];

Or use a while loop:

或者使用while循环:

while (list($day, $month, $year, $location, $description, $event_link, $ticket_link) = each($gig)) {

Or use extract() (not recommended):

或者使用extract()(不推荐):

foreach ($gig as $giginfo) {
    extract($giginfo);

As for your array, you are using a syntax that is only available in PHP 5.4. So you will need to use array() syntax instead:

对于您的数组,您使用的语法仅在PHP 5.4中可用。所以你需要使用array()语法:

<?php

$gig = array(
    array(28,12,2013,
        'The Firebug - Leicester', 
        'with more awesome bands',
        'www.facebook.com',
        'www.seetickets.com'
    ),
    array(
        19,04,2014,
        'Pi Bar - Leicester', 
        '(acts tbc)',
        'www.facebook.com',
        ''
    ),
);

?>

更多相关文章

  1. 在多维数组中查找最小值并返回键
  2. 如何使用变量访问多维数组中的某些元素?
  3. 键入提示 - 指定对象数组
  4. 切出多维数组的一部分
  5. 仅获取单元素php数组中的值的最佳方法。
  6. 如何从其他文件调用数组
  7. php如何判断数组["a","b","c"]中是否含有"a"?
  8. 如何从databse中提取数据到2d数组中?
  9. 如果key在变量中,PHP如何从数组中获取值

随机推荐

  1. Android外派(安卓外派) — 长年提供安卓开
  2. android 用到的技巧集
  3. Android lint 删除无用图片文件和配置文
  4. 【Android】Java四种线程池的使用
  5. android 笔记 --- 自定义Android主题风格
  6. android 瀛︿範绗旇10鈥斺€擷ML瑙f瀽
  7. android 网络图片双缓存
  8. Android签到功能的实现
  9. [Android实例] Android 开发者面试题-广
  10. Android L Developer Preview