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) {
        ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 ZYNQ7020双核FLAHS烧写的问题
  • ¥20 ue 5 中想要实现第一人称人物左右行走摆动的效果,摄像头只向右摆动一次(关键词-结点)
  • ¥15 钢岔管添加弹性约束模拟围岩作用
  • ¥15 AD9164瞬时带宽1.8G,怎么计算出来?
  • ¥15 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数