Incorrect PHP returned the Webservice data to the array dimension.

Source: Internet
Author: User
Incorrect array dimension returned by PHP for retrieving Webservice data I used the nusoap plug-in to read webservice, but an error occurred. When the returned array is greater than one group, the returned value is correct. However, when only one group of array data is returned, the dimension changes, resulting in incorrect array length obtained by count. The code is as follows: when there are two groups of data, the result is as follows: PHPcode PHP retrieves Webservice data and returns an incorrect array dimension.
I used the nusoap plug-in to read webservice, but something went wrong.
When the returned array is greater than one group, the returned value is correct. However, when only one group of array data is returned, the dimension changes, resulting in incorrect array length obtained by count.
The code is as follows:
When there are two groups of data, the result is as follows:
PHP code
  Array ([getTrafficResult] => Array ([trafficWay] => Array ([0] => Array ([Station] => 4828,4830, 4868 [Line] => 2908,2906 [Price] => 10.5 [Alltime] => 10 [ChangeCount] => 1 [Type] => [Station_name] => Tsim Sha Tsui subway station # Admiralty subway station # Causeway Bay subway station [Line_name] => Tsuen Wan line, hong Kong Island Line [Allstation] => 0 | Wan Chai subway station [Stationcount] => 1, 2 [ction] => Central Subway Station # Chai Wan subway station [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] => Beijing Road, gyeongdong Road # Victoria Park, ustdin Road [Line_name] => sinaba 110 [Allstation] => New World Center, cabisbury Road # Old garinway Road, qizarhan Road South # Hong Kong Science Museum, qinxian Road South # livestock station, qingxian Road north # Undersea Tunnel Toll Plaza [Stationcount] => 6 [ction] => Tsuen Wan [Time] => 20 [Distance] => 2552 [Lineremark] => 0 [Addstartinfo] => 334 #5 #0 [Addendinfo] => 337 #5 #0 ))))


However, when there is only one group of data, one dimension is missing:

PHP code
  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] => Tsim Sha Tsui subway station # Hongyi subway station # Sha Tin subway station # New City Plaza [Line_name] => walking, West Rail Line, East Rail line, walk [Allstation] => 0 | 0 | Mong Kok East subway station # Kowloon Tong subway station # Dawai subway station | 0 [Stationcount] =>, [Direction] => 0 # Hongshu subway station # luomazhou subway station #0 [Time] => 6, 3, 15, 2 [Distance] => 36, 8810,163 [Lineremark] => 0 #0 #0 # exit from A [Addstartinfo] => 0 [Addendinfo] => 0 )))


I used $ arr ['gettrafficresult'] ['trafficway '] to retrieve data and obtain the length. The first one gets 2 in length, which is correct, but the second one gets 16, the number of fields.

How can this problem be solved?

------ Solution --------------------
From the example, you only need to judge isset ($ arr ['gettrafficresult'] ['trafficway '] [0]) to distinguish
------ Solution --------------------
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.