- var_dump: documentation ( source)
<?php
$data = <<<DATA
<file_allegati>
<allegato id="0" planimetria="0" type="foto">
<id>0</id>
<file_path>https://##.jpg </file_path>
</allegato>
<allegato id="1" planimetria="1" type="planimetria">
<id>1</id>
<file_path>https://##.jpg </file_path>
</allegato>
</file_allegati>
DATA;
function set_planimetrie($allegati)
{
$result = '';
$xml = new SimpleXMLElement($allegati);
foreach ($xml->children() as $allegato) {
if ((string)$allegato['type'] === 'planimetria' && (string)$allegato['planimetria'] === "1") {
if ($result !== '') {
$result .= ',';
}
$result .= $allegato->file_path;
}
}
return $result;
}
var_dump(set_planimetrie($data));