PHP Array Question: Fatal Error - Cannot use string offset a
Posted: Wed Apr 01, 2009 7:28 am
I searched around the internet for an explanation of this but I just can't seem to understand what I am doing wrong. I'm making a SOAP call to an API and getting these results returned:
Array ( [SearchResult] => Array ( [Id] => Array ([0]=> 077BE86E-372F-4390-8F0A-EC163706D8FC [1] => 318A39E4-EC95-4DA9-B92E-4C081E10A974 [2] => D4489F50-760C-403D-AB79-3C962356F784 ) ) )
Array
If I use this code I don't get an error, I get a count of 1:
if I change the code to this, I get the string offset error
I read this about the string offset error:
PHP5 Error message that is caused by attempting to assign a value to an array element of a variable that is declared as a string.
It's kind of Greek to me but it sounds like the error is when you try to assign something as a string first and then give it an array value? I guess I am confused as I am not assigning $SearchCventResults as anything but an array - it passes variables as XML to a function in the API and returns the results as an array. --> $SearchCventResults = $client->call("Search", $searchXML);
Any help would be greatly appreciated.
Array ( [SearchResult] => Array ( [Id] => Array ([0]=> 077BE86E-372F-4390-8F0A-EC163706D8FC [1] => 318A39E4-EC95-4DA9-B92E-4C081E10A974 [2] => D4489F50-760C-403D-AB79-3C962356F784 ) ) )
Array
If I use this code I don't get an error, I get a count of 1:
Code: Select all
print_r($SearchCventResults);
echo "<br>" . count($SearchCventResults['SearchResult']);
echo "<hr>";Code: Select all
print_r($SearchCventResults);
echo "<br>" . count($SearchCventResults['SearchResult']['Id']);
echo "<hr>";PHP5 Error message that is caused by attempting to assign a value to an array element of a variable that is declared as a string.
It's kind of Greek to me but it sounds like the error is when you try to assign something as a string first and then give it an array value? I guess I am confused as I am not assigning $SearchCventResults as anything but an array - it passes variables as XML to a function in the API and returns the results as an array. --> $SearchCventResults = $client->call("Search", $searchXML);
Any help would be greatly appreciated.