RJS Posted September 28, 2007 Share Posted September 28, 2007 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 https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/ Share on other sites More sharing options...
marcus Posted September 28, 2007 Share Posted September 28, 2007 Well by default array keys start at 0 and automatically increment depending on how many values are listed inside. Try just counting $return[searchResults] Link to comment https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/#findComment-357231 Share on other sites More sharing options...
RJS Posted September 28, 2007 Author Share Posted September 28, 2007 echo count($result[searchResults]); Returns 1 no matter if 0, 1 or more than 1 results are returned. And by results I mean Address hits. Link to comment https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/#findComment-357244 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 try $num_of_res = $result['searchResults']['ArrayOfString'] ? count($result['searchResults']['ArrayOfString']) : 0; Link to comment https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/#findComment-357256 Share on other sites More sharing options...
RJS Posted September 28, 2007 Author Share Posted September 28, 2007 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 https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/#findComment-357263 Share on other sites More sharing options...
sasa Posted September 28, 2007 Share Posted September 28, 2007 it is same with if($result['searchResults']['ArrayOfString']) $num_of_res = count($result['searchResults']['ArrayOfString']) else $num_of_res = 0; Link to comment https://forums.phpfreaks.com/topic/71053-multi-dimensional-array-help/#findComment-357292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.