PHP has no named arguments, so the short answer is no. There are two solutions that I can find, although not all are fantastic.
You can define your function to accept its arguments as an array, for example this :
function image($img) { $tag = '<img src="' . $img['src'] . '" '; $tag .= 'alt="' . ($img['alt'] ? $img['alt'] : '') .'">'; return $tag; } $image = image(array('src' => 'cow.png', 'alt' => 'cows say moo')); $image = image(array('src' => 'pig.jpeg'));
This method, unfortunately, requires changing your function, and as a result, I do not like it. Another option is to use this wrapper class , which allows you to use named arguments in one of the following ways:
$obj->method(array('key' => 'value', 'key2' => 'value2')); $obj->method(':key = value', ':key2 = value2');
marcog
source share