|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hi
I have a problem with calling functions: <?php function solution1($var1) { // some code } function solution2($var2) { // some code } function solution3($var3) { // some code } if ($function == 'solution1' or $function == 'solution2' or $function == 'solution3') { $my_solution = $function($var); # this supposed to call one of "solution" functions, right? } ?> suggestions? thanks. -afan |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Robin Vickery wrote: > On 19/10/2007, afan pasalic <afan@afan.net> wrote: > >> hi >> I have a problem with calling functions: >> >> <?php >> function solution1($var1) { >> // some code >> } >> >> function solution2($var2) { >> // some code >> } >> >> function solution3($var3) { >> // some code >> } >> >> if ($function == 'solution1' or $function == 'solution2' or $function == >> 'solution3') >> { >> $my_solution = $function($var); # this supposed to call one of >> "solution" functions, right? >> } >> ?> >> >> suggestions? >> > > suggestions for what? > > What is your problem? If you set $function to 'solution1' and run your > code, it will indeed execute solution1(). > > -robin > the problem is that this code doesn't work. and I was asking where is the problem, or can I do it this way at all. :-) -afan |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Jay Blanchard wrote: > [snip] > <?php > function solution1($var1) { > // some code > } > > function solution2($var2) { > // some code > } > > function solution3($var3) { > // some code > } > > if ($function == 'solution1' or $function == 'solution2' or $function == > 'solution3') > { > $my_solution = $function($var); # this supposed to call one of > "solution" functions, right? > } > ?> > [/snip] > > I don't think you can put a function name in a variable and call it like > $function($var). You'd be better of with a case statement in one > function and call the proper solution (quick syntax, may need a little > fixing; > > function my_solution($function, $var){ > switch $function{ > case function1: > ...do stuff... > break; > case function1: > > > etc..... > } > } > that's exactly what I'm doing now. though, I was thinking if it's possible. :-( thanks jay |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Jay Blanchard wrote:
> [snip] > [snip] > <?php > function solution1($var1) { > // some code > } > > function solution2($var2) { > // some code > } > > function solution3($var3) { > // some code > } > > if ($function == 'solution1' or $function == 'solution2' or $function == > 'solution3') > { > $my_solution = $function($var); # this supposed to call one of > "solution" functions, right? > } > ?> > [/snip] > > I don't think you can put a function name in a variable and call it like > $function($var). You'd be better of with a case statement in one > function and call the proper solution (quick syntax, may need a little > fixing; > > function my_solution($function, $var){ > switch $function{ > case function1: > ...do stuff... > break; > case function1: > > > etc..... > } > } > [/snip] > > And call it like this; > > my_solution('function1', $var); > actually, I did a little bit different: switch($function) { case 'solution1': solution1($var1); break; case 'solution2': solution2($var2); break; case 'solution3': solution3($var3); break; } ;-) -afan |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 19/10/2007, afan pasalic <afan@afan.net> wrote:
> hi > I have a problem with calling functions: > > <?php > function solution1($var1) { > // some code > } > > function solution2($var2) { > // some code > } > > function solution3($var3) { > // some code > } > > if ($function == 'solution1' or $function == 'solution2' or $function == > 'solution3') > { > $my_solution = $function($var); # this supposed to call one of > "solution" functions, right? > } > ?> > > suggestions? suggestions for what? What is your problem? If you set $function to 'solution1' and run your code, it will indeed execute solution1(). -robin |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
2007. 10. 19, péntek keltezéssel 11.15-kor afan pasalic ezt Ãrta:
> hi > I have a problem with calling functions: > > <?php > function solution1($var1) { > // some code > } > > function solution2($var2) { > // some code > } > > function solution3($var3) { > // some code > } > > if ($function == 'solution1' or $function == 'solution2' or $function == > 'solution3') > { > $my_solution = $function($var); # this supposed to call one of > "solution" functions, right? > } > ?> what's wrong with this? greets Zoltán Németh > > suggestions? > > thanks. > > -afan > |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
[snip]
<?php function solution1($var1) { // some code } function solution2($var2) { // some code } function solution3($var3) { // some code } if ($function == 'solution1' or $function == 'solution2' or $function == 'solution3') { $my_solution = $function($var); # this supposed to call one of "solution" functions, right? } ?> [/snip] I don't think you can put a function name in a variable and call it like $function($var). You'd be better of with a case statement in one function and call the proper solution (quick syntax, may need a little fixing; function my_solution($function, $var){ switch $function{ case function1: ...do stuff... break; case function1: etc..... } } |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
[snip]
[snip] <?php function solution1($var1) { // some code } function solution2($var2) { // some code } function solution3($var3) { // some code } if ($function == 'solution1' or $function == 'solution2' or $function == 'solution3') { $my_solution = $function($var); # this supposed to call one of "solution" functions, right? } ?> [/snip] I don't think you can put a function name in a variable and call it like $function($var). You'd be better of with a case statement in one function and call the proper solution (quick syntax, may need a little fixing; function my_solution($function, $var){ switch $function{ case function1: ...do stuff... break; case function1: etc..... } } [/snip] And call it like this; my_solution('function1', $var); |
|
![]() |
| Outils de la discussion | |
|
|