how can i extract the values from an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sathumenon
    New Member
    • Jul 2007
    • 4

    how can i extract the values from an array

    Hi

    Am a new bie - and in need of some helo
    Please find the attachment here.
    I would like to know how I can extract the values from this and list properly?

    What I need is to list the Hotel ID, Name ,etc .

    Can any one help me?

    Many thanks
    Sathish
    Attached Files
    Last edited by sathumenon; Jan 7 '10, 06:57 PM. Reason: typo
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Is that a PHP array or will you be having to read the data from a text file?

    Comment

    • erayfield
      New Member
      • Jan 2010
      • 4

      #3
      that looks like a var_dump - if so you will need to loop through the array. It is a multi-level array, so something like this:

      Code:
      /**
      * loops through array/multi-dimensional arrays
      *@param array array to loop through
      *@return string in key value pairs, or null
      *@see [url]http://www.communitymx.com/content/article.cfm?page=2&cid=7CD16[/url]
      **/
      function loopThroughArray($passedArray) 
      {  
           $retVal = '';
           //validate is array
           if (!is_array($passedArray) { return null; }
           //loop through array
            foreach ($passedArrayas $key => $value ) 
            {  
               if (!is_array($value)) 
               {  
                       // if it isn't an array show $key and $value  
                       $retVal .= ' <br />' . $key; 
                       $retVal .= '  ->  ' . $value; 
               }
                else 
                { 
                      // if it is an array set up the key 
                     $retVal .= '<hr color="red">‘ . $key.’</strong>‘;  
                      //then process $value again will same function. 
                       foreach_loop($value);  
               }  
          }
           return $retVal;
       }
      Last edited by Dormilich; Jan 8 '10, 07:10 AM. Reason: Please use [code] tags when posting code

      Comment

      • sathumenon
        New Member
        • Jul 2007
        • 4

        #4
        Hi

        this comes in as a string, more like a webservice. I am not sure how to explain it. I hop this helps?

        Comment

        • sathumenon
          New Member
          • Jul 2007
          • 4

          #5
          I got some idea from this. Thanks a lot Erayfield!
          I think I will give a try using this and the link You have mentioned.

          :)

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            The data you posted is in the same format as provided by the web service? If so I'd tell the web service provider that they need to seriously reconsider.

            Comment

            Working...