duanbipu7601 2014-12-10 08:28
浏览 22

在PHP中需要一个用于动态MULTIDIMENSIONAL ARRAY显示的显示功能

QS1. The results mention below is from one array ( got from WEBSERVICE CALL using SOAP). i have some confusion regarding accessing elements from the array. As seen from the results, sometime results comes as an ARRAY (in second result) where as sometimes results comes without array index (first results). SO how can I use the best method for displaying elements like array["AirportCode"] for getting accurate results and display output TO user.

*********************
RESULTS SET-1
********************

  Array
    (
    [SegmentIndicator] => 1
    [Airline] => Array
    (
    [AirlineCode] => SG
    [AirlineName] => SpiceJet
    [AirLineRemarks] => SG Star Coupon
    )

    [FlightNumber] => 894
    [FareClass] => K
    [Origin] => Array
    (
    [AirportCode] => GAU
    [AirportName] => Borjhar
    [Terminal] =>
    [CityCode] => GAU
    [CityName] => Guwahati
    [CountryCode] => IN
    [CountryName] => India
    )

    [Destination] => Array
    (
    [AirportCode] => DEL
    [AirportName] => Indira Gandhi Airport
    [Terminal] => 1C
    [CityCode] => DEL
    [CityName] => Delhi
    [CountryCode] => IN
    [CountryName] => India
    )

    [DepTIme] => 2014-12-26T11:05:00
    [ArrTime] => 2014-12-26T14:00:00
    [ETicketEligible] => 1
    [Duration] => 02:55
    [Stop] => 0
    [Craft] => 738
    [Status] => Confirmed
    [OperatingCarrier] => SG
    )
*****************************************
RESULTS SET-2
****************************************
Array
(
[0] => Array
(
[SegmentIndicator] => 1
[Airline] => Array
(
[AirlineCode] => AI
[AirlineName] => Air India
[AirLineRemarks] => This JetAirways series are operated by JetLite
)

[FlightNumber] => 401
[FareClass] => Y
[Origin] => Array
(
[AirportCode] => DEL
[AirportName] => Indira Gandhi Airport
[Terminal] => 3
[CityCode] => DEL
[CityName] => Delhi
[CountryCode] => IN
[CountryName] => India
)

[Destination] => Array
(
[AirportCode] => CCU
[AirportName] => Calcutta
[Terminal] => 2
[CityCode] => CCU
[CityName] => Kolkata
[CountryCode] => IN
[CountryName] => India
)

[DepTIme] => 2014-12-31T07:00:00
[ArrTime] => 2014-12-31T09:05:00
[ETicketEligible] => 1
[Duration] => 00:00
[Stop] => 0
[Craft] => 321
[Status] => Confirmed
[OperatingCarrier] => AI
)

[1] => Array
(
[SegmentIndicator] => 1
[Airline] => Array
(
[AirlineCode] => 9W
[AirlineName] => Jet Airways
[AirLineRemarks] => This JetAirways series are operated by JetLite
)

[FlightNumber] => 2363
[FareClass] => H
[Origin] => Array
(
[AirportCode] => CCU
[AirportName] => Calcutta
[Terminal] =>
[CityCode] => CCU
[CityName] => Kolkata
[CountryCode] => IN
[CountryName] => India
)

[Destination] => Array
(
[AirportCode] => GAU
[AirportName] => Borjhar
[Terminal] =>
[CityCode] => GAU
[CityName] => Guwahati
[CountryCode] => IN
[CountryName] => India
)

[DepTIme] => 2014-12-31T10:45:00
[ArrTime] => 2014-12-31T11:55:00
[ETicketEligible] => 1
[Duration] => 00:00
[Stop] => 0
[Craft] => 738
[Status] => Confirmed
[OperatingCarrier] => 9W
)
  • 写回答

1条回答 默认 最新

  • douqin7086 2014-12-10 08:46
    关注

    I'll write a loop that will work both case. I'll show only one var -> AirportCode <-

    first, i'll have a var called myArray with the array.

    $myArray = .... // Do what you need to populate it.
    

    Now let's make a cicle.

    for ($i = 0; $i < count($myArray); $i++){
     if(isset($myArray[$i]['AirportCode'])){
      print  $myArray[$i]['AirportCode'];
    }
    }
    

    You need however to test this code.

    评论

报告相同问题?

悬赏问题

  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据