控制器矩阵查看 - ZF

时间:2014-07-24 16:21:23

标签: php arrays zend-framework matrix

控制器

我的矩阵是$mes

print_r($mes);


Array ( 
   [0] => Array ( 
          [0] => 0 
          [1] => 0 
          [2] => 0 
          [3] => 0 
          [4] => 0
          [5] => 0 
          [6] => 3 
          [7] => 1 
          [8] => 0 
          [9] => 0 
          [10] => 0 
          [11] => 0 
          [12] => 0 
      ) 
   ) 
 Array ( 
      [1] => Array ( 
            [0] => 0 
            [1] => 0 
            [2] => 0 
            [3] => 0 
            [4] => 0 
            [5] => 0 
            [6] => 2 
            [7] => 0 
            [8] => 0 
            [9] => 0 
            [10] => 0 
            [11] => 0 
            [12] => 0 
         ) 
     )

发送数据以查看:

  

$ this-> view-> repMes = $ mes;

在视图中

<?php print_r($this->repMes); ?>

Array ( 
  [0] => 0 
  [1] => 0
  [2] => 0 
  [3] => 0 
  [4] => 0 
  [5] => 0 
  [6] => 2
  [7] => 0 
  [8] => 0 
  [9] => 0 
  [10] => 0 
  [11] => 0 
  [12] => 0 
)

可以证明缺少矩阵的第一部分,因为它可以解决?

2 个答案:

答案 0 :(得分:0)

我相信你想要一个二维数组,但看着你的代码,我看到你有两个不同的数组。所以你$ mes变量指向第二个数组,这就是为什么你只看到视图中的第二个数组。你应该把控制器中的数组作为:

 $mes =   Array ( 
               [0] => Array ( 
                      [0] => 0 
                      [1] => 0 
                      [2] => 0 
                      [3] => 0 
                      [4] => 0
                      [5] => 0 
                      [6] => 3 
                      [7] => 1 
                      [8] => 0 
                      [9] => 0 
                      [10] => 0 
                      [11] => 0 
                      [12] => 0 
                  )
              [1] => Array ( 
                        [0] => 0 
                        [1] => 0 
                        [2] => 0 
                        [3] => 0 
                        [4] => 0 
                        [5] => 0 
                        [6] => 2 
                        [7] => 0 
                        [8] => 0 
                        [9] => 0 
                        [10] => 0 
                        [11] => 0 
                        [12] => 0 
                     )
            )

答案 1 :(得分:0)

请注意,当您打印矩阵时,它会显示为两个不同的数组,这是因为您的代码流未发送正确的数组。

  1. 您的数组“$ mes”应为:
  2. Array ( 
        [0] => Array ( 
            [0] => 0, 
            [1] => 0, 
            [2] => 0, 
            [3] => 0, 
            [4] => 0,
            [5] => 0, 
            [6] => 3, 
            [7] => 1, 
            [8] => 0, 
            [9] => 0, 
            [10] => 0, 
            [11] => 0, 
            [12] => 0 ),
       [1] => Array ( // See here you should have the second subindex, and not the closing and reopening
            [0] => 0, // of "Array"
            [1] => 0, 
            [2] => 0, 
            [3] => 0, 
            [4] => 0, 
            [5] => 0, 
            [6] => 2, 
            [7] => 0, 
            [8] => 0, 
            [9] => 0, 
            [10] => 0, 
            [11] => 0, 
            [12] => 0) 
     )
    

    我建议使用临时计数器变量来检查你的“打印”是否在重复

    有些人喜欢:

    echo "<pre> Loop --> \n";
    print_r($mes);
    echo "End Loop\n</pre>";
    

    这样你就可以检查真正的数组。