开发者

How to Display the below given array in a List of records?

HI All

I have an array as

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
                )

   开发者_如何学JAVA         [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] => 
                )

        )

)

Now I want this Array to be displayed in a List of records, i.e. below given namings are headers of the fields to be displayed in a single row

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

Here the Two Rows TO be Displayed will be for array MyArray[0] and MyArray[1], I Need it to be work dynamically..

I M Getting Confused In Iterating the Array..Please help me in this


I would recommend using a foreach statement and you can nest them to iterate the deeper arrays.

Something like this (note this obviously won't run and I only skimmed over your array structure)

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


Sounds like a need for a recursion function that loops through the array and prints its values like:

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

Just an idea, you may want to play around with it to do what you desire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜