如何在记录列表中显示下面给出的数组?

时间:2011-04-10 07:13:40

标签: php arrays

全部

我有一个数组

MyArray
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => COMPANY NAME
                    [docatrtype_name] => COMPANY NAME
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1
                    [Value] => 1
                )

            [vendor] => 22
            [lpos] => Array
                (
                    [0] => Array
                        (
                            [0] => REQUESTED BY
                            [docatrtype_name] => REQUESTED BY
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Himself
                            [Value] => Himself
                        )

                    [1] => Array
                        (
                            [0] => VENDOR NAME
                            [docatrtype_name] => VENDOR NAME
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 22
                            [Value] => 22
                        )

                    [2] => Array
                        (
                            [0] => AMOUNT
                            [docatrtype_name] => AMOUNT
                            [1] => 1
                            [docatrtypetype_id] => 1
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1000
                            [Value] => 1000
                        )

                    [3] => Array
                        (
                            [0] => PRIORITY
                            [docatrtype_name] => PRIORITY
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                    [4] => Array
                        (
                            [0] => ADDITIONAL DESCRIPTION
                            [docatrtype_name] => ADDITIONAL DESCRIPTION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Testing The Update
                            [Value] => Testing The Update
                        )

                    [5] => Array
                        (
                            [0] => PAYMENT TERMS & CONDITION
                            [docatrtype_name] => PAYMENT TERMS & CONDITION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 2
                            [Value] => 2
                        )

                    [6] => Array
                        (
                            [0] => EXPECTED DATE OF APPROVAL
                            [docatrtype_name] => EXPECTED DATE OF APPROVAL
                            [1] => 3
                            [docatrtypetype_id] => 3
                            [2] => 1
                            [mustenter] => 1
                            [3] => 11/04/2011
                            [Value] => 11/04/2011
                        )

                    [7] => Array
                        (
                            [0] => COMPANY NAME
                            [docatrtype_name] => COMPANY NAME
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                )

            [1] => Array
                (
                    [0] => LPO NUMBER
                    [docatrtype_name] => LPO NUMBER
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => PO1
                    [Value] => PO1
                )

            [2] => Array
                (
                    [0] => LPO DATE
                    [docatrtype_name] => LPO DATE
                    [1] => 3
                    [docatrtypetype_id] => 3
                    [2] => 1
                    [mustenter] => 1
                    [3] => 2011-04-09 17:05:44
                    [Value] => 2011-04-09 17:05:44
                )

            [3] => Array
                (
                    [0] => LPO AMT
                    [docatrtype_name] => LPO AMT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1000
                    [Value] => 1000
                )

            [4] => Array
                (
                    [0] => PENDING AMT
                    [docatrtype_name] => PENDING AMT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1000
                    [Value] => 1000
                )

            [5] => Array
                (
                    [0] => PRIORITY
                    [docatrtype_name] => PRIORITY
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1
                    [Value] => 1
                )

            [6] => Array
                (
                    [0] => AMOUNT
                    [docatrtype_name] => AMOUNT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 200
                    [Value] => 200
                )

            [7] => Array
                (
                    [0] => BENEFICIARY NAME
                    [docatrtype_name] => BENEFICIARY NAME
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 0
                    [mustenter] => 0
                    [3] => Self
                    [Value] => Self
                )

            [8] => Array
                (
                    [0] => PAYMENT AS
                    [docatrtype_name] => PAYMENT AS
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 2
                    [Value] => 2
                )

            [9] => Array
                (
                    [0] => VENDOR NAME
                    [docatrtype_name] => VENDOR NAME
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 0
                    [Value] => 0
                )

            [10] => Array
                (
                    [0] => FINAL PAYMENT
                    [docatrtype_name] => FINAL PAYMENT
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 0
                    [mustenter] => 0
                    [3] => 
                    [Value] => 
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => COMPANY NAME
                    [docatrtype_name] => COMPANY NAME
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1
                    [Value] => 1
                )

            [vendor] => 22
            [lpos] => Array
                (
                    [0] => Array
                        (
                            [0] => REQUESTED BY
                            [docatrtype_name] => REQUESTED BY
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Himself
                            [Value] => Himself
                        )

                    [1] => Array
                        (
                            [0] => VENDOR NAME
                            [docatrtype_name] => VENDOR NAME
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 22
                            [Value] => 22
                        )

                    [2] => Array
                        (
                            [0] => AMOUNT
                            [docatrtype_name] => AMOUNT
                            [1] => 1
                            [docatrtypetype_id] => 1
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1000
                            [Value] => 1000
                        )

                    [3] => Array
                        (
                            [0] => PRIORITY
                            [docatrtype_name] => PRIORITY
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                    [4] => Array
                        (
                            [0] => ADDITIONAL DESCRIPTION
                            [docatrtype_name] => ADDITIONAL DESCRIPTION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Testing The Update
                            [Value] => Testing The Update
                        )

                    [5] => Array
                        (
                            [0] => PAYMENT TERMS & CONDITION
                            [docatrtype_name] => PAYMENT TERMS & CONDITION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 2
                            [Value] => 2
                        )

                    [6] => Array
                        (
                            [0] => EXPECTED DATE OF APPROVAL
                            [docatrtype_name] => EXPECTED DATE OF APPROVAL
                            [1] => 3
                            [docatrtypetype_id] => 3
                            [2] => 1
                            [mustenter] => 1
                            [3] => 11/04/2011
                            [Value] => 11/04/2011
                        )

                    [7] => Array
                        (
                            [0] => COMPANY NAME
                            [docatrtype_name] => COMPANY NAME
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                    [8] => Array
                        (
                            [0] => REQUESTED BY
                            [docatrtype_name] => REQUESTED BY
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Himself
                            [Value] => Himself
                        )

                    [9] => Array
                        (
                            [0] => VENDOR NAME
                            [docatrtype_name] => VENDOR NAME
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 22
                            [Value] => 22
                        )

                    [10] => Array
                        (
                            [0] => AMOUNT
                            [docatrtype_name] => AMOUNT
                            [1] => 1
                            [docatrtypetype_id] => 1
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1000
                            [Value] => 1000
                        )

                    [11] => Array
                        (
                            [0] => PRIORITY
                            [docatrtype_name] => PRIORITY
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                    [12] => Array
                        (
                            [0] => ADDITIONAL DESCRIPTION
                            [docatrtype_name] => ADDITIONAL DESCRIPTION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 0
                            [mustenter] => 0
                            [3] => Testing The Update
                            [Value] => Testing The Update
                        )

                    [13] => Array
                        (
                            [0] => PAYMENT TERMS & CONDITION
                            [docatrtype_name] => PAYMENT TERMS & CONDITION
                            [1] => 5
                            [docatrtypetype_id] => 5
                            [2] => 1
                            [mustenter] => 1
                            [3] => 2
                            [Value] => 2
                        )

                    [14] => Array
                        (
                            [0] => EXPECTED DATE OF APPROVAL
                            [docatrtype_name] => EXPECTED DATE OF APPROVAL
                            [1] => 3
                            [docatrtypetype_id] => 3
                            [2] => 1
                            [mustenter] => 1
                            [3] => 11/04/2011
                            [Value] => 11/04/2011
                        )

                    [15] => Array
                        (
                            [0] => COMPANY NAME
                            [docatrtype_name] => COMPANY NAME
                            [1] => 4
                            [docatrtypetype_id] => 4
                            [2] => 1
                            [mustenter] => 1
                            [3] => 1
                            [Value] => 1
                        )

                )

            [1] => Array
                (
                    [0] => LPO NUMBER
                    [docatrtype_name] => LPO NUMBER
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => PO1
                    [Value] => PO1
                )

            [2] => Array
                (
                    [0] => LPO DATE
                    [docatrtype_name] => LPO DATE
                    [1] => 3
                    [docatrtypetype_id] => 3
                    [2] => 1
                    [mustenter] => 1
                    [3] => 2011-04-09 17:05:44
                    [Value] => 2011-04-09 17:05:44
                )

            [3] => Array
                (
                    [0] => LPO AMT
                    [docatrtype_name] => LPO AMT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1000
                    [Value] => 1000
                )

            [4] => Array
                (
                    [0] => PENDING AMT
                    [docatrtype_name] => PENDING AMT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 800
                    [Value] => 800
                )

            [5] => Array
                (
                    [0] => PRIORITY
                    [docatrtype_name] => PRIORITY
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 1
                    [Value] => 1
                )

            [6] => Array
                (
                    [0] => AMOUNT
                    [docatrtype_name] => AMOUNT
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 800
                    [Value] => 800
                )

            [7] => Array
                (
                    [0] => BENEFICIARY NAME
                    [docatrtype_name] => BENEFICIARY NAME
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 0
                    [mustenter] => 0
                    [3] => Self
                    [Value] => Self
                )

            [8] => Array
                (
                    [0] => PAYMENT AS
                    [docatrtype_name] => PAYMENT AS
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 1
                    [mustenter] => 1
                    [3] => 2
                    [Value] => 2
                )

            [9] => Array
                (
                    [0] => VENDOR NAME
                    [docatrtype_name] => VENDOR NAME
                    [1] => 1
                    [docatrtypetype_id] => 1
                    [2] => 1
                    [mustenter] => 1
                    [3] => 0
                    [Value] => 0
                )

            [10] => Array
                (
                    [0] => FINAL PAYMENT
                    [docatrtype_name] => FINAL PAYMENT
                    [1] => 4
                    [docatrtypetype_id] => 4
                    [2] => 0
                    [mustenter] => 0
                    [3] => 
                    [Value] => 
                )

        )

)

现在我希望这个数组显示在记录列表中,即下面给出的命名是要在一行中显示的字段的标题

Vendor Name |Beneficiary Name | LPO NUMBER | LPO DATE | LPO AMOUNT | AMOUNT | ADDITIONAL DESCRIPTION

这里要显示的两行将是数组MyArray [0]和MyArray [1],我需要它动态地工作..

我在迭代阵列时感到困惑。请帮助我

2 个答案:

答案 0 :(得分:1)

我建议使用foreach语句,你可以嵌套它们来迭代更深层的数组。

像这样的东西(注意这显然不会运行,我只是略过你的数组结构)

foreach(MyArray as $companies)
{
   foreach($companies as $company)
   {
      echo $company[0] //Company name
      foreach($company as $details)
      {
          echo $details[0] //requested by
      }
   }
}

答案 1 :(得分:0)

听起来像是需要一个循环遍历数组并打印其值的递归函数,如:

function printValues(array $array)
{
   foreach($array as $key => $value)
   {
       if(is_array($value))
       {
           printValues($value);
       }
       else
       {
         // print values
         // add some specific $key checks if ever they're specially handled or want to not print them
         // if(#key == 'Value')
         //     do stuff
       }
   }
 }

只是一个想法,你可能想要玩它来做你想做的事。