This is an example of the data in my array. Notice that the <person></person> appears twice, and in fact, can appear several or hundreds (if need be) times in the data.
code:----------------------------------------------------------<root>
<person>
Bob
<phone type="voice">222-2222</phone>
<phone type="mobile">333-3333</phone>
<email>bob@example.com</email>
</person>
<person>
Alice
<phone type="voice">444-4444</phone>
<phone type="mobile">555-5555</phone>
<email>alice@example.com</email>
</person>
</root>
I want to return all the data in the <person></person> tags in my array. By using this code:
PHP:---------------------------------------------------------
$personList =& $data["ROOT"][0]["PERSON"];
foreach ($personList as $person)
{
echo "\n<br>" . $person["NAME"][0]["value];
echo "n<br>" . $person["PHONE"][0]["TYPE"];
echo "n<br>" . $person["PHONE"][0]["value"];
echo "n<br>" . $person["PHONE"][1]["TYPE"];
echo "n<br>" . $person["PHONE"][1]["value"];
echo "n<br>" . $person["EMAIL"][0]["value"];
}
it will return all the tags for both Bob and Alice (apart from the "value" data but thats a different thread)
I want to assign all the data in the <person></person> tag to a variable so I can use it later in my script.
I tried the code below but it only returns Alice. i.e. returns the last result instead of both (or all) results.
Is it possible for it to return all the results in the one string?
PHP:------------------------------------------------------
$personList =& $data["ROOT"][0]["PERSON"];
foreach ($personList as $person)
{
$list =
"\n" . $person["NAME"][0]["value"] .
"\n" . $person["PHONE"][0]["TYPE"] .
"\n" . $person["PHONE"][0]["value"] .
"\n" . $person["PHONE"][1]["TYPE"] .
"\n" . $person["PHONE"][1]["value"] .
"\n" . $person["EMAIL"][0]["value"] ;
mail($to, $subj, $body);
}