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

时间:2010-04-23 18:21:05

标签: php

使用Brian的建议如下:

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>";
        }

我从数组中得到以下输出,这是不对的:

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

任何进一步的建议。

荷马。

你好,

提前感谢您的帮助。

以下是我的基于$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
      ) 
 )

我想显示数组的元素,使用(我认为)foreach语句循环遍历每一行但是我无法使它工作,理想情况下,我想回应这样的事情

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.";

然而,文本链接会出现数组中的许多行。

任何和所有建议都表示赞赏 - 我正在努力让我的脑袋绕过多维数组:(

荷马。

2 个答案:

答案 0 :(得分:1)

来自TriLLi的修改

1)你不需要$ key,因为你从不使用它 - 事实上php会报告警告或通知

2)如果您不需要

,请避免使用错误抑制运算符@

3)你也想要<tr>标签,对吧?

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 :(得分:0)

使用如下代码 foreach($rowq as $key => $value)
{
echo @"".$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.";
}