SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOAP call and arrays returned??

    Having a problem with a SOAP call and < 1 fields returned.

    Normally a SOAP call returns an array and everything works fine. So with more than 1 <field>, i can loop through the <field> tags (as expected)..

    However, with exactly 1 <field>, i loop through the child elements of the first <field>.

    Please compare the RoomTypeAvail node

    The soap library makes the following array with just one field
    Code:
    [RatePlanAvail] => Array
                            (
                                [RatePlan] => STD
                                [IsPackage] => false
                                [RateDescription] => asdfsdf
                                [InfoText] => 
                                [RoomTypes] => Array
                                    (
                                        [RoomTypeAvail] => Array
                                            (
                                                [RoomType] => DIsdfasdf
                                                [RoomDescription] => asdfasdf
                                                [InfoText] => 
                                                [Available] => true
                                                [Rates] => sdfgsfd
    
                                            )
    
                                    )
    
                            )
    This is with more fields and the one that works.
    Code:
    [RatePlanAvail] => Array
                            (
                                [RatePlan] => Sqwer
                                [IsPackage] => false
                                [RateDescription] => asdfsdf
                                [InfoText] => 
                                [RoomTypes] => Array
                                    (
                                        [RoomTypeAvail] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [RoomType] => wrerew
                                                        [RoomDescription] => wqer
                                                        [InfoText] => 
                                                        [TotalTax] => 0
                                                        [Available] => true
                                                        [Rates] => sdgfsdfg
    
                                                    )
    
                                                [1] => Array
                                                    (
                                                        [RoomType] => sdfg
                                                        [RoomDescription] => sdfg
                                                        [InfoText] => 
                                                        [TotalRate] => 190
                                                        [TotalTax] => 0
                                                        [Available] => true
                                                        [Rates] => dsfgdfg
    
                                                    )
    
                                            )
    
                                    )
    
                            )
    Now i know a solution on
    http://nl3.php.net/manual/en/functio...call.php#75797

    but it doesn't work for me
    Code:
       foreach(getArrayFromResponse($roomsAvailable) as $rooms => $value) {
    //echo all our values
    
    }
    Any tips, advice pointers???

    sorry for the long post.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try:
    Code php:
    function getArrayFromResponse($data)
    {
        return is_array($data)?$data:array($data);
    }
    Saul

  3. #3
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @php_deamon, i hear what you are saying. But your solution doesn't fix it.

    RoomTypeAvail will always be an array, but not a "nested array" so i need something

    if $data is a nested array
    then ....

    else
    $data equals the values of our array


    How can i check if the $data in an array is an array???

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if (count($data) > 1) { //do stuff }

  5. #5
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found a solution

    Code:
    function getArrayFromResponse($data)
    {
        $test = is_array($data)?$data:array($data);
        if(is_array($test[0])) {
            $data = $data;
        } else { 
            $data = array($data);
        }
        return $data;
    }

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm...

    PHP Code:
    if (count($data) > 1) { ... etc ... 
    This would return true if $data held an array or any other type for that matter,

    > How can i check if the $data in an array is an array???


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •