doulu3399 2010-04-23 18:21
浏览 20
已采纳

PHP数组 - 在数组中显示元素的一些其他问题

Using Brian's suggestion below:

foreach($qs as $value){
                echo "<tr>".$value['qnum']." is the questions number and the question text is ".$value['qtext'].". The page and q values are ".$value['page']." and ".$value['questions']." respectively.</tr>";
        }

I get the following output from the array, which isn't right:

8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively.8 is the questions number and the question text is I know how what I do fits into my team's objectives. The page and q values are 1 and q8 respectively

Any further suggestions.

Homer.

Hi again,

Thanks in advance for the help.

Here is my array based on $rowq:

Array (
 [0] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       )
 [1] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       ) 
 [2] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       ) 
 [3] => Array (
       [questions] => q8 
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1
       )
 [4] => Array (
       [questions] => q8
       [qnum] => 8
       [qtext] => I know how what I do fits into my team's objectives
       [page] => 1  
       )
 [5] => Array (
      [questions] => q8 
      [qnum] => 8 
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1 
      )
 [6] => Array (
      [questions] => q8 
      [qnum] => 8
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1
      )
 [7] => Array (
      [questions] => q8
      [qnum] => 8
      [qtext] => I know how what I do fits into my team's objectives
      [page] => 1
      ) 
 )

I would like to display elements of the array, looping through each row using (i think) the foreach statement but I can't get it working, ideally, I would like to echo something like this

echo "<tr>".$rowq[qnum]." is the questions number and the question text is ".$rowq[qtext].".  The page and q values are ".$rowq[page]." and ".$rowq[questions]." respectively.";

And that link of text would appear however many rows the array has in it.

Any and all advice appreciated - I'm struggling like heck to get my head around multi-dimensional arrays :(

Homer.

  • 写回答

2条回答 默认 最新

  • dongzhi7641 2010-04-23 18:34
    关注

    modifications from TriLLi

    1) you don't need the $key since you never use it - in fact php will report a warning or notice

    2) avoid using the error suppression operator, @, if you don't need to

    3) also you wanted <tr> tags, right?

    foreach($rowq as $value){
                echo "<tr><td>".$value['qnum']." is the questions number 
      and the question text is ".$value['qtext'].". The page and q values are".
    $value['page']." and ".$value['questions']." respectively.</td></tr>";
        } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)