PHP取Webservice数据返回数组维度不正确
我用nusoap插件读取webservice,但是出现了问题。
当返回的数组大于1组时,返回正确,但是当数组数据只有1组是,维度就发生了变化,导致count获取数组长度就不正确。
代码如下:
当有2组数据时,结果如下:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> Array ( [getTrafficResult] => Array ( [trafficWay] => Array ( [0] => Array ( [Station] => 4828,4830,4868 [Line] => 2908,2906 [Price] => 10.5 [Alltime] => 10 [ChangeCount] => 1 [Type] => 2,2 [Station_name] => 尖沙咀地铁站#金钟地铁站#铜锣湾地铁站 [Line_name] => 荃湾线,港岛线 [Allstation] => 0|湾仔地铁站 [Stationcount] => 1,2 [Direction] => 中环地铁站#柴湾地铁站 [Time] => 5,5 [Distance] => 2172,2017 [Lineremark] => 0#0 [Addstartinfo] => 0 [Addendinfo] => 0 ) [1] => Array ( [Station] => 2655,2847 [Line] => 1084 [Price] => 9.3 [Alltime] => 30 [ChangeCount] => 0 [Type] => 1 [Station_name] => 北京道,广东道#维多利亚公园,告士打道 [Line_name] => 新巴110 [Allstation] => 新世界中心,梳士巴利道#加连威老道,漆咸道南#香港科学馆,漆咸道南#牲口站,漆咸道北#海底隧道收费广场 [Stationcount] => 6 [Direction] => 筲箕湾 [Time] => 20 [Distance] => 2552 [Lineremark] => 0 [Addstartinfo] => 334#5#0 [Addendinfo] => 337#5#0 ) ) ) )
但是当只有一组数据时,就少了一维:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> Array ( [getTrafficResult] => Array ( [trafficWay] => Array ( [Station] => 4828,4827,4823,4855,4573 [Line] => 3190,2914,4227,3730 [Price] => 8 [Alltime] => 28 [ChangeCount] => 1 [Type] => 5,2,2,5 [Station_name] => 尖沙咀地铁站#尖东地铁站#红磡地铁站#沙田地铁站#新城市广场 [Line_name] => 步行,西铁线,东铁线,步行 [Allstation] => 0|0|旺角东地铁站#九龙塘地铁站#大围地铁站|0 [Stationcount] => 0,1,4,0 [Direction] => 0#红磡地铁站#落马洲地铁站#0 [Time] => 6,3,15,2 [Distance] => 360,1125,8810,163 [Lineremark] => 0#0#0#从A出口 [Addstartinfo] => 0 [Addendinfo] => 0 ) ) )
我用$arr['getTrafficResult']['trafficWay']取数据并取得长度,第一个获取长度为2,正确,但是第二个获取就成了16,成了 字段的个数了。
请问这个问题如何解决
------解决方案--------------------
从例子看,你只需判断 isset($arr['getTrafficResult']['trafficWay'][0])即可区分
------解决方案--------------------

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
