|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I am trying to create function that will assign several variables during it's process, but I cannot seem to get those variables to display outside of the function.
function example ($input_var) { if ($input_var == option1) { $new_var = new_desired_output1; } else { $new_var = new_desired_output2; } } Then I define $input_var and have a call to the function in the page: $input_var = some_var; example ($input_var); Then later in the page: echo $new_var; But the last bit does not work? Is there a trick to get the new variable out of the function? I can get it to work inside the function, but not outside?? Thanks
__________________
Rob |
|
||||
|
Assuming you are coding in PHP: If $new_var is assigned before the function begins, you can tell the function to use the the "global" version of $new_var rather than creating a local copy using the global operator.
PHP Code:
__________________
The best way to learn anything, is to question everything. |
|
|||
|
In your situation i think i'd be tempted to return an array of values from the function rather than use global variables. Just makes the function more independent and reusable. What if you decided to move that function to another file? You'd have to remember to move all the related variables also.
Something to think about. Mike |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A little PHP function that might be helpful | shannonlp | Web Programming Discussion Forum | 2 | 08-01-2007 04:54 PM |
| PHP help - function call | bilabong | Web Programming Discussion Forum | 0 | 07-22-2007 07:56 AM |
| Form and Function | grease | Graphics & Design Discussion Forum | 0 | 09-19-2005 12:36 AM |
| Everything You Must Know About ColdFusion Variables | WPW_Feedbot | Graphics & Design Discussion Forum | 0 | 08-19-2005 12:37 AM |
| php redirect variables | scollett | Web Programming Discussion Forum | 11 | 01-20-2005 11:57 PM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |