Streamlining Passing Values into Function...

I am trying to streamline the way I pass variables into a function.

I want to be able to do this:


So I am looking for a way to take the variables being passed into a function, and to convert them into their name value pairs. I want to do this in such a way that I can use it for all my functions and I don't have to hard code stuff. Is this possible? Bad Idea?

Who is Participating?
James LooneyConnect With a Mentor Sr. Programmer/AnalystCommented:
You could pass an array into your function.

$values = array('name'=>'John', 'age'=>28, 'hair'=>'brown');

then you would have:

function some_function($params)
     echo $params['name'].'<br>';
     echo $params['age'].'<br>';
Beverley PortlockCommented:
It is not so much a bad idea as a pointless one.... at least I cannot see what you would put into the function in terms of code. To handle general data coming in you need a general function and it was proven back in th 1930s that no such general functionality is possible (Turing et al.)

I feel that I'm missing the point here. What are you actually trying to achieve?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.