I’ve got this block which is appears over and over again in my code with slight changes, i would like to use a function, but as far as i know when writing a function you set the number of arguments,
the block of code im using is
$type = $xml->response->williamhill->class->type;
$type_attrib = $type->attributes();
echo "<h2>".$type_attrib['name']."</h2>";
echo "<h2>".$type_attrib['url']."</h2>";
the main difference is that the first line which drills down through an xml document, it may drill down further, in other places, is that possible to do with a function ?
ie. it may need to look like this in some places :
$xml->response->williamhill->class->type->market->participant
You could use XPath:
Usage:
Also, if any part of this path is always the same, you can move that part into the function, i.e.