Curious if someone could help with this issue I am having. I am constructing a URL to pass to a 3rd party script, and have the need to use a multidimensional array now. My code works fine with an associative array, but I'm not sure how to modify this to get the results I want.
I'll try to post the important code so that it makes sense. This is the bit of code that errors because the information being passed is not a string, the foreach() is the line that errors in:
function create_query_string($url,$values)
{
$sep = strpos($url,'?') === FALSE ? '?' : '&';
foreach ( $values as $key => $val ) $url .= "$key=" . urlencode( $val ) . "&";
return $url;
}
I'll use the above function to construct a generic URL with:
function api_call($script,$vars)
.......
$url = create_query_string('http://domain.com/'.$script.'.php?',$vars);
Here is the multidimensional array causing an issue:
$package = array(
'client' => $client,
'user' => $user,
'options' => $option_list = array(
1 => '1',
2 => '4',
)
);
Then send it all to the 3rd party API:
$result = api_call('addpackage',$package);
Soo... the issue here as I see it is the options array must need to be converted to a string first?
hopefully that wasn't too confusing the way I laid it all out. Any help is appreciated.