PHP: Function like array constructor -
i've not used php couple years—my focus has been on c, c++, objective-c, ruby & ecmascript. i'm having night of keeping mind fresh experimenting in other languages.
i came across illustration on php.net of casting arrays object enable accessing it's values key if instance variable:
$obj = (object)array('foo' => 'bar', 'property' => 'value');
as exercise, i'd create function takes same arguments array
, returns "array" casted object. like:
function o_array(\* variable amount of key=>value args array()*\) { homecoming (object)array.call(self, arguments); }
i don't know how build function takes variable amount of key=>value arguments in php. in advance advice.
update hope next changes in future since see php's main strength beingness flexibility , general craziness (also weakness). named parameters not supported: php language meeting regarding named params among other items.
php doesn't allow named arguments not possible. array not function language construct, that's why it's place can utilize key value assignment
php arrays casting variable-length-arguments
No comments:
Post a Comment