When attempting to extract data from XML using node names containing hyphens, a "Warning: Invalid argument supplied for foreach()" error may arise. This occurs due to PHP's naming convention restrictions.
To address this, the PHP manual recommends encapsulating such element names within braces and apostrophes. For instance, in your case, instead of:
foreach ($xml->custom-field-value as $milestone) { ... }
You should write:
$xml->{'custom-field-value'}
This will allow you to access and iterate over elements with hyphenated node names seamlessly.
The above is the detailed content of How to Access XML Nodes with Hyphens in PHP?. For more information, please follow other related articles on the PHP Chinese website!