Streamlining Passing Values into Function...

Posted on 2008-11-17
Last Modified: 2012-05-05
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?

Question by:interclubs
    LVL 34

    Expert Comment

    by:Beverley Portlock
    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?
    LVL 6

    Accepted Solution

    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>';

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now