| | |
optional variables in php functions
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Hi everybody, there's a question I would ask about php functions.
I would like to know if it is possible to have optional variable in functions.
Let's say, for instance, that I have:
In some cases I would recall the function, inputting values for "a","b" and "c", while in some other cases I would just input values for "a" and "b".
In both cases the function is working, but when I input just two values I have the following error shown on the page, before the code is executed:
Warning: Missing argument 3 for my_fun(), called in...
Is there a way to say that $c is optional, in order to avoid the message to be displayed?
Thank you very much,
s
I would like to know if it is possible to have optional variable in functions.
Let's say, for instance, that I have:
PHP Syntax (Toggle Plain Text)
function my_fun($a,$b,$c){ various stuff }
In some cases I would recall the function, inputting values for "a","b" and "c", while in some other cases I would just input values for "a" and "b".
In both cases the function is working, but when I input just two values I have the following error shown on the page, before the code is executed:
Warning: Missing argument 3 for my_fun(), called in...
Is there a way to say that $c is optional, in order to avoid the message to be displayed?
Thank you very much,
s
IT goes green
(sustainable informatic development)
(sustainable informatic development)
to make it optional, you have to set the varible with a value in the function.
ex.
ex.
PHP Syntax (Toggle Plain Text)
<?php function test( $a,$b,$c='') { //do what you need } ?>
Easy, fast, clean and working.
Thank you very much!
Thank you very much!
IT goes green
(sustainable informatic development)
(sustainable informatic development)
![]() |
Similar Threads
- Open In New Window Php (PHP)
- So many errors! (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: uploaded file moving to new directory
- Next Thread: Restricting access to list & detail pages
Views: 894 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date development directory display download dynamic echo email error file files folder form forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






