John Davidson

php - Arrays from XML

0 comments
Message:


Maybe someone could help?


I am extracting data from XML that's been returned via curl_init, got this far with the code that's been provided foreach($xml->Outputs->Company->Type as $quoteBlock)


foreach($xml->Outputs->Company->Type as $quoteBlock)
{

foreach($quoteBlock->Company as $arr)
{

$companyName=(string)$arr->Name;
$amount=(string)$arr->samount;
$quote[$blockDesc][$companyName]=$premium;

}

}

This is the response I get with each company which is A and so has an amount


Array
(
[] => Array
(
[A] => 25.59
[B] => 24.53
[C] => -
[D] => 24.57
[E] => 29.11
[F] => 25.59
)

Is there a way to make a variable for each company, for example, $acompany is the value number 25.59 from company A?



My Answer:
>children() as $child) {
$data[] = [
'name' => (string) $child->name,
'age' => (int) $child->age,
'gender' => (string) $child->gender
];
}

This code snippet loops through each child element in the XML and extracts the 'name', 'age', and 'gender' attributes into an associative array. You can then use the $data array to access the extracted data.

Rate this post

3 of 5 based on 3950 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us