1

I am running the following code:

$attributes = $xmlTable2->attributes();
foreach ($attributes as $key => $value) {
    $xmlTable1->addAttribute($key, $value);
}

But it causes an error:

Warning: SimpleXMLElement::addAttribute(): Attribute already exists in ... on line 100
Buildfile: /.../vendor/propel/propel1/generator/build.xml

How do I override the value of an existing attribute?

NobleUplift
  • 5,631
  • 8
  • 45
  • 87

1 Answers1

2

Easiest way is to just use the attributes() function that is part of the SimpleXML object on the element you want to get the attributes for.

$xmlTable1->elementYouWantAttrsFor->attributes()->attrName = newAttrValue;

or if each $xmlTable1 element is what you want

$xmlTable1->attributes()->attrName = newAttrValue;

Here is the documentation. The comments show how to do this.

Zarathuztra
  • 3,215
  • 1
  • 20
  • 34