Jump to content

Multi-Dimensional Array Help


RJS

Recommended Posts

I am using NuSoap to make a WSDL request to a server (that I don't own).

require_once('lib/nusoap.php');
$client = new soapclient('site.wsdl', true);
$param = array('address' => $address,'apt'=>$apt,'city'=>$city,'state'=>$state,'zip'=>$state);
$result = $client->call('getAddressData', array('parameters' => $param), '', '', false, true);

 

$results is a multi dimensional array.

 

If there is no results from the search print_r($result) displays:

 

Array
(
    [searchResults] => 
)

 

If one result is returned print_r($result) displays:

Array
(
    [searchResults] => Array
        (
            [ArrayOfString] => Array
                (
                    [0] => Array
                        (
                            [string] => Array
                                (
                                    [0] => 11101 WEST 580 SOUTH STREET
                                    [1] => 
                                    [2] => OREM
                                    [3] => UT
                                    [4] => 84458
                                    [5] => STATUS
                                )
                        )
                )
        )
)

 

If more than one result is return print_r($result) returns:

Array
(
    [searchResults] => Array
        (
            [ArrayOfString] => Array
                (
                    [0] => Array
                        (
                            [string] => Array
                                (
                                    [0] => 11101 WEST 580 SOUTH STREET
                                    [1] => 
                                    [2] => OREM
                                    [3] => UT
                                    [4] => 84458
                                    [5] => STATUS
                                )
                        )

                    [1] => Array
                        (
                            [string] => Array
                                (
                                    [0] => 11101 WEST 580 SOUTHWEST STREET
                                    [1] => 
                                    [2] => OREM
                                    [3] => UT
                                    [4] => 84458
                                    [5] => STATUS
                                )
                        )

                    [2] => Array
                        (
                            [string] => Array
                                (
                                    [0] => 11101 WEST 1580 EAST STREET
                                    [1] => 
                                    [2] => OREM
                                    [3] => UT
                                    [4] => 84458
                                    [5] => STATUS
                                )
                        )
                    [3] => Array
                        (
                            [string] => Array
                                (
                                    [0] => 11101 WEST 5560 NORTH STREET
                                    [1] => 
                                    [2] => OREM
                                    [3] => UT
                                    [4] => 84458
                                    [5] => STATUS
                                )
                        )
                )
        )
)

How can I tell if there are 0, 1 or more than one results returned?

 

I tried this: count($return[searchResults][ArrayOfString])

but that returns a 1 even if there are no results returned.

 

What is the most efficient way to tell how many results there are in my array?

 

Thank You.

 

Link to comment
Share on other sites

try

$num_of_res = $result['searchResults']['ArrayOfString'] ? count($result['searchResults']['ArrayOfString']) : 0;

 

Worked like a charm.  I appreciate it.  Can you briefly explain the code? Especially with the "?".  I want to make sure I understand it.

 

Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.