1

I do the next SOAP call:

$soapclient = new SoapClient(self::getParameterByKey(self::$WDSL));

$response = $soapclient->getAllProductsAndOffers(array("province_id" => $province_id, "city_id" => 
$city_id, "code" => $code, "favoritos" => $favoritos, "tipo" => $tipo));

THE CONNECTIONOF MY SOAP IS GOING FINE. NO PROBLEM.

I get the result:

object(stdClass)#10 (1) { ["getAllProductsAndOffersResult"]=> object(stdClass)#9 (3) { ["data"]=> object(stdClass)#8 (1) { ["ProductsOffers"]=> array(3) { [0]=> object(stdClass)#7 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(10) "davidtest1" ["created_date"]=> string(19) "2014-04-30T00:15:05" ["id"]=> int(7) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(123) } [1]=> object(stdClass)#6 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(8) "alava-01" ["created_date"]=> string(19) "2014-04-27T01:57:18" ["id"]=> int(5) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(50) ["province_id"]=> int(33) ["tipo"]=> string(1) "O" ["value"]=> float(500) } [2]=> object(stdClass)#5 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(6) "da-003" ["created_date"]=> string(19) "2014-04-27T01:05:39" ["id"]=> int(4) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(2000) } } } ["err"]=> bool(false) ["message"]=> string(2) "ok" } }

The Result to convert the object to array is:

array(1) { ["getAllProductsAndOffersResult"]=> array(3) { ["data"]=> array(1) { ["ProductsOffers"]=> array(3) { [0]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(10) "davidtest1" ["created_date"]=> string(19) "2014-04-30T00:15:05" ["id"]=> int(7) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(123) } [1]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(8) "alava-01" ["created_date"]=> string(19) "2014-04-27T01:57:18" ["id"]=> int(5) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(50) ["province_id"]=> int(33) ["tipo"]=> string(1) "O" ["value"]=> float(500) } [2]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(6) "da-003" ["created_date"]=> string(19) "2014-04-27T01:05:39" ["id"]=> int(4) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(2000) } } } ["err"]=> bool(false) ["message"]=> string(2) "ok" } }

To convert I use the next function I found in internet:

public static function objectToArray($d) {
        if (is_object($d)) {
            // Gets the properties of the given object
            // with get_object_vars function
            $d = get_object_vars($d);
        }

        if (is_array($d)) {
            /*
                * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            return array_map("self::" . __FUNCTION__, $d);
        }
        else {
            // Return array
            return $d;
        }
    }

My question is why do I get all data like float(...), string(...), int(...)?

Can I avoid this and really my array containts only the real data without the format?

I want this kind of information:

["ProductsOffers"]=> array(3) { 
    [0]=> array(13) { 
        ["bussiness_id"]=> 1 
        ["city_id"]=> 899
        ["codigo"]=> "davidtest1" 
        ["created_date"]=> "2014-04-30T00:15:05" 
        ["id"]=> 7 
        ["img_url"]=> "" 
        ["latitud"]=> 41.385589
        ["longitud"]=> 2.168745
        ["nombre"]=> "" 
        ["porcentaje"]=> 0 
        ["province_id"]=> 33
        ["tipo"]=> "P" 
        ["value"]=> 123
    } 
    ...
}

NO THIS what it is returned for the soap call:

["ProductsOffers"]=> array(3) { 
    [0]=> array(13) { 
        ["bussiness_id"]=> int(1) 
        ["city_id"]=> int(899) 
        ["codigo"]=> string(10) "davidtest1" 
        ["created_date"]=> string(19) "2014-04-30T00:15:05" 
        ["id"]=> int(7) 
        ["img_url"]=> string(0) "" 
        ["latitud"]=> float(41.385589) 
        ["longitud"]=> float(2.168745) 
        ["nombre"]=> string(0) "" 
        ["porcentaje"]=> float(0) 
        ["province_id"]=> int(33) 
        ["tipo"]=> string(1) "P" 
        ["value"]=> float(123) 
    } 
    ...
}
1
  • Are you confused by print_r()'s output? That is real data. Commented Apr 30, 2014 at 19:04

1 Answer 1

1

You can use var_dump($returnedArray); function and the output should show you the result with type.

Sign up to request clarification or add additional context in comments.

2 Comments

I added the next code: $res = var_dump(Utilitats::objectToArray($response)); print_r($res); and it is returning the same, maybe I thihk I dont understand you. Anyway The results of above I got using var_dump
the information was in cache, now I could return a right information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.