dsg7513
2017-09-05 15:37
浏览 56
已采纳

循环遍历每个多维数组并回显一个数组

Multi dimensional array:

Array
(
    [CalculateOverheadDoorSpringsResult] => Array
        (
            [SpringForce] => Array
                (
                    [InputData] => Array
                        (
                            [CalculationMode] => Expert
                            [CalculationVersion] => V100_ProofOfConceptVersion
                            [TrackSystemCode] => 1
                            [TrackSystemTypeDescription] => Normal Lift
                            [DoorWidth_mm] => 5000
                            [DoorHeight_mm] => 5000
                            [LiftHeight_mm] => 0
                            [TrackPitch_deg] => 0
                            [DoorWeight_kg] => 300
                            [VerticalComponentWeight_kg] => 33.33
                            [BottomSectionHeight_mm] => 610
                            [TensionSet] => false
                            [SpringCount] => 2
                            [ShaftConnectorCount] => 1
                            [ShaftDiameterCode] => 1
                            [ShaftDiameterDescription] => Shaft 1" (25.4 mm)
                            [SurfaceFinishCode] => 3
                            [SurfaceFinishDescription] => Powder coated
                            [CycleCount] => 20000
                            [SolutionTypeCode] => 1
                            [SolutionTypeDescription] => Simplex Identical
                            [OptimalSolutionOnly] => false
                            [DrumSpecification] => Automatic
                            [DrumFlexiForceCode] => FFNL18
                            [DrumCustomCode] => 
                            [DrumCustomFlatMomentArm_mm] => 0
                            [DrumCustomHighMomentArm_mm] => 0
                            [DrumCustomFlatWindings] => 0
                            [DrumCustomSipralWindings] => 0
                            [DrumCustomSafetyWindings] => 0
                            [EnforceFlexiForceCableRuling] => True
                            [InputDataValid] => true
                        )

                    [OutputData] => Array
                        (
                            [CalculationVersionBaseData] => V1.3.113
                            [CalculationVersionSolver] => V1.0.1
                            [TorqueTotal_Nmm_turn] => 17123
                            [Turns] => 12.8
                            [EnforceFlexiForceCableRuling] => True
                            [CableDiameter_mm] => 4
                        )

                    [Solutions] => Array
                        (
                            [Solution] => Array
                                (
                                    [0] => Array
                                        (
                                            [SolutionID] => 0604d089-e8cd-47e4-b331-e74373e23861
                                            [SpringCount] => 2
                                            [SpringWeightTotal_kg] => 69.77
                                            [ActualCycleCount] => 35900
                                            [SpringUnit] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring LHW 09,5x95x1810mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 34.89
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 9.5
                                                                    [Length_mm] => 1810
                                                                    [Diameter_mm] => 95.25
                                                                    [Direction] => L
                                                                    [ArticleId] => VL95-3-1810PP
                                                                    [SpringWeight_kg] => 34.89
                                                                )

                                                        )

                                                    [1] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring RHW 09,5x95x1810mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 34.89
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 9.5
                                                                    [Length_mm] => 1810
                                                                    [Diameter_mm] => 95.25
                                                                    [Direction] => R
                                                                    [ArticleId] => VR95-3-1810PP
                                                                    [SpringWeight_kg] => 34.89
                                                                )

                                                        )

                                                )

                                        )

                                    [1] => Array
                                        (
                                            [SolutionID] => f495d32f-567e-41a9-ad10-b5b35e1ba20f
                                            [SpringCount] => 2
                                            [SpringWeightTotal_kg] => 69.71
                                            [ActualCycleCount] => 35000
                                            [SpringUnit] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring LHW 09,5x152x1170mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 34.86
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 9.5
                                                                    [Length_mm] => 1170
                                                                    [Diameter_mm] => 152.4
                                                                    [Direction] => L
                                                                    [ArticleId] => VL95-6-1170PP
                                                                    [SpringWeight_kg] => 34.86
                                                                )

                                                        )

                                                    [1] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring RHW 09,5x152x1170mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 34.86
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 9.5
                                                                    [Length_mm] => 1170
                                                                    [Diameter_mm] => 152.4
                                                                    [Direction] => R
                                                                    [ArticleId] => VR95-6-1170PP
                                                                    [SpringWeight_kg] => 34.86
                                                                )

                                                        )

                                                )

                                        )

                                    [2] => Array
                                        (
                                            [SolutionID] => 6b97f4eb-1fa2-4885-a93d-63f24d108f1f
                                            [SpringCount] => 2
                                            [SpringWeightTotal_kg] => 93.74
                                            [ActualCycleCount] => 98400
                                            [SpringUnit] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring LHW 10,0x152x1490mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 46.87
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 10
                                                                    [Length_mm] => 1490
                                                                    [Diameter_mm] => 152.4
                                                                    [Direction] => L
                                                                    [ArticleId] => VL100-6-1490PP
                                                                    [SpringWeight_kg] => 46.87
                                                                )

                                                        )

                                                    [1] => Array
                                                        (
                                                            [Type] => Simplex
                                                            [Qty] => 1
                                                            [Description] => 1 x Ass. Spring RHW 10,0x152x1490mm Pwdr. Plugged
                                                            [SpringWeightUnitTotal_kg] => 46.87
                                                            [Spring] => Array
                                                                (
                                                                    [Wire_mm] => 10
                                                                    [Length_mm] => 1490
                                                                    [Diameter_mm] => 152.4
                                                                    [Direction] => R
                                                                    [ArticleId] => VR100-6-1490PP
                                                                    [SpringWeight_kg] => 46.87
                                                                )

                                                        )

                                                )

                                        )

                                )

                            [!SolutionsFound] => true
                            [!SolutionCount] => 3
                        )

                    [!XMLVersion] => 1.0
                    [!CreateTimeStamp] => 2017-09-05T15:27:35Z
                    [!XMLID] => 0a1116c0-e140-47f2-acc5-6f8322d3d5f6
                    [!SystemError] => false
                    [!SystemErrorMessage] => 
                )

        )

)

Need to loop through each [Solutions] => Array, [OutputData] => Array and to show results in a simple table, almost like in the picture:

enter image description here

My question is how too loop through multi dimensional array [CalculateOverheadDoorSpringsResult] and echo only the solutions and outputdata arrays? Solutions will always alternate, it ca be 1 solution, 2, 3 or even more.

I was thinking like something, but at least it is a start:

<?php $array = $result['CalculateOverheadDoorSpringsResult'];
    foreach ($array as $item) { ?>
    <tr>
        <td><?php echo $item['InputData']['DrumFlexiForceCode'] . PHP_EOL; ?></td>
        <td><?php echo $item['OutputData']['Turns'] . PHP_EOL; ?></td>
        <td><?php echo $item['InputData']['SurfaceFinishDescription'] . PHP_EOL; ?></td>
        <td><?php echo $item['InputData']['CycleCount'] . PHP_EOL; ?></td>
    </tr>
    <?php } ?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题