[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Streamlining Passing Values into Function...

Posted on 2008-11-17
2
Medium Priority
?
292 Views
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:

SomeFunction("Name=John","Age=28","hair=brown");

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?

0
Comment
Question by:interclubs
2 Comments
 
LVL 34

Expert Comment

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

Accepted Solution

by:
James Looney earned 2000 total points
ID: 22979949
You could pass an array into your function.

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

then you would have:

function some_function($params)
{
     echo $params['name'].'<br>';
     echo $params['age'].'<br>';
}
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 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