douchun1859 2015-06-18 22:53
浏览 64
已采纳

我的php语法出了什么问题? [关闭]

I'm trying to display products on my page I was hoping to store products and their attributes in a 2d array then include them on the page and display them. This way I could add products just by editing the 2d array.

here's my catalog.php

<?php
$varProduct = array
(
// title, style, price, number of xsmalls, number of small, number of medium, number of large, number of xl, number small picture path, medium picture path, large picture path, sale 

array("Title" , 10213 , 100, 0,0,1,1,0, "/womens/tops/s/2.png", "/womens/tops/s/2.jpg", "/womens/tops/s/2.jpg", 50  )
array("Title" , 10213 , 100, 0,0,1,1,0, "/womens/tops/s/2.png", "/womens/tops/s/2.jpg", "/womens/tops/s/2.jpg", 50  )

)
?>

I want to display the title index [0] the picture index [8] and the price index [2]

here's myPage.php

<h3 style="margin-bottom:20px; left:10px; position:relative;"> New Women's designs and colors </h2>


        <?php
        include("catalog.php");
        for($x =0; $x < count($varProduct); $x++ )
        {
        echo $varProdct[x][0];  
        }   

        ?>

I get an error on the page ) Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' in C:\wamp\www\sparta\WomensNewArrivalCatalog.php on line 7 Call Stack

how can I display what I need to display I don't see where my syntax is wrong.

edit: after adding the comma I get a

( ! ) Notice: Use of undefined constant x - assumed 'x' in C:\wamp\www\sparta\myPage.php on line 101 Call Stack

Time Memory Function Location

1 0.0000 144880 {main}( ) ..\myPage.php:0

  • 写回答

2条回答 默认 最新

  • dongliang1996 2015-06-18 23:00
    关注

    You are missing comma "," after first index of main array and a semicolon at the end of main array. Here how your code should look like:

    $varProduct = array
    (
       array("Title" , 10213 , 100, 0,0,1,1,0, "/womens/tops/s/2.png", "/womens/tops/s/2.jpg", "/womens/tops/s/2.jpg", 50  ),
       array("Title" , 10213 , 100, 0,0,1,1,0, "/womens/tops/s/2.png", "/womens/tops/s/2.jpg", "/womens/tops/s/2.jpg", 50  )
    
    ); 
    

    [edit]: There is another syntax errors in your other myPage.php file as well. such as missing $ for variable x at echo statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab