Jump to content

Foreach to get array value


crims0nluv

Recommended Posts

$result=
Array (

    * => [1] => [2] => [3] => Array ( [contact] => {{1}} [contact-ATTR] => Array (
    * => Array ( [name] => rose => [email][email protected] ) [1] => Array ( [name] => Sylph => [email][email protected] ) ) ) ) 


$result = array();  //  <-------------------You clear out the result variable and 
                          //                               then try to operate on each element in the array?
foreach ($result as $contact) {
            $result[] = array('name' => (string) $contact['name'], 'email' => (string) $contact['email']);
        }
        return $result; 

 

Also is the code you posted the exact code you are using?  The array doesn't look like it should even get set in the first place--strings without quotes etc.

Hi,

Thanks for your reply :)

 

Actually what I'm trying to do it to get the function simplexml_load_string works in PHP4.

 

So what I did is that ,  ( I got the code from somewhere else)

include('xmlobject.php');

$xml = new Xml;

$source = $str;

$out = $xml->parse($source, NULL);

print_r($out);

 

        foreach ($out->contact as $contact) {

            $result[] = array('name' => (string) $contact['name'], 'email' => (string) $contact['email']);

        }

        return $result;

    }

 

the $out gives me the array  :

  Array (

 

    * => [1] => [2] => [3] => Array ( [contact] => {{1}} [contact-ATTR] => Array (

    * => Array ( [name] => rose => [email protected] ) [1] => Array ( [name] => Sylph => [email protected] ) ) ) )

 

 

I put the xmlobject.php at

http://www.alldogsworld.com/xmlobject.txt

 

The code is quite long. Or do you have any other method to replace the function simplexml_load_string  in php4 ?

 

Thanks again

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.