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

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

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条回答 默认 最新

  • dqrfdl5708 2017-09-05 15:51
    关注

    You can loop over Solutions like this:

    foreach($result['CalculateOverheadDoorSpringsResult']['SpringForce']['Solutions']['Solution'] as $solution) {
        ...
    }
    

    and loop over OutputData like:

    foreach($result['CalculateOverheadDoorSpringsResult']['SpringForce']['OutputData'] as $output) {
        ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,