如何使用PHP更新xml的值

i have this .xml file..

<product>
    <id>4021</id>
    <product_code>1220211</product_code>
    <barcode>1220211</barcode>
    <title>sera Pond granulat - храна на гранули</title>
    <price>71.65</price>
    <meta_title>sera Pond granulat - храна на гранули</meta_title>
    <meta_description>sera Pond granulat, 21 000 мл</meta_description>
</product>

With this php code i want to create meta decsription of all products.

<?php
  $xml=simplexml_load_file("zoo.xml") or die("Error: Cannot create object");
       foreach($xml->children() as $desc) { 
         echo $desc->title . "  "; 
         echo $desc->price . " лв. "; 
       echo ' some text here' . "<br>";
   } 
?>

How to update all meta_description in the same file with created text. Thank you

If you just need to change the text of the last element, you can access it the same way as you fetch the value for your echo statements...

foreach($xml->product as $desc) {
    echo $desc->title . "  ";
    echo $desc->price . " лв. ";
    $desc->meta_description = $desc->title . "  ".$desc->price . " лв. ";
}

Don't forget to save the data afterwards back to the file

$xml->asXML("zoo.xml");