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 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能