473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Creating optional arguments

Let's say I have

function dosomething ($var1, $var2, $var3) {

...

}

How do I make $var3 optional so that I can pass only 2 arguments and
still have it work?
Oct 15 '05 #1
3 6533
On Sat, 15 Oct 2005 21:57:52 GMT, Mazin07 <ma*****@gmail.com> wrote:
Let's say I have

function dosomething ($var1, $var2, $var3) {

...

}

How do I make $var3 optional so that I can pass only 2 arguments and
still have it work?


http://www.php.net/manual/en/functions.arguments.php
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 15 '05 #2
Mazin07 wrote:
Let's say I have

function dosomething ($var1, $var2, $var3) {

...

}

How do I make $var3 optional so that I can pass only 2 arguments and
still have it work?

function dosomething($var1, $var2, $var3='somevalue'){
..
}
Oct 16 '05 #3
Just a side note that you probably aready might know(im not always too
bright).
If you have more then one 'optional' argument:
function dosomething($var1, $var2='value2', $var3='somevalue')

They must be used in order. So if you need value3, you will need to fill
value2 also.

Siv Hansen wrote:
Mazin07 wrote:
Let's say I have

function dosomething ($var1, $var2, $var3) {

...

}

How do I make $var3 optional so that I can pass only 2 arguments and
still have it work?


function dosomething($var1, $var2, $var3='somevalue'){
..
}

Oct 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rob Long | last post by:
Hey, I've just noticed a somewhat annoying feature with PHP5 type hinting. You cannot hint types on optional arguments like this: class MyClass { function someFunc(Type1 $arg1, Type2 $arg2...
7
by: JT | last post by:
how can i declare a function that will accept an optional parameter? something like: function newFunc(strValue1, strValue2) --where strValue2 is optional. thanks much.
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
0
by: Sean Richards | last post by:
Python 2.3.4 (#1, May 29 2004, 17:05:23) on linux2 Getting some strange behaviour with keyword arguments for optional arguments in extension modules. See the simple test case below ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
3
by: Winshent | last post by:
I want to pass optional arguments to build up varios strings, is this possible? look at arrTBL(1,3) in the code below: =========================================== Public Function...
12
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
6
by: Rob Hoelz | last post by:
So these two functions are different: void foo(void); and void foo(); because the first one allows no arguments, but the second does. My question is: In the implementation of the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.