you have to know what the function prototypes mean, and it is very easy to
understand:

int function(string varname, mixed varname2[[, array varname3], int
varname4]);

means the function returns a variable of type integer, which is the same as
int. Just two names for the same thing.
if int is specified, it also can be a resource like a database connection
handle or a file handle.

then comes the function name. in this case it's "function".
then the parameter list. in this case, the first two arguments are required,
the last two arguments are optional,
which is shown by the [] brackets.a paramater definition first shows the
type and then the name of the parameter.

string varname, mixed varname2[[, array varname3], int varname4]]

string varname = first argument is required and has to be a string
mixed varname2 = second argument is required and could be any type or a list
of types.
                             e.g.: some functions could be called with an
array or a string.
array varname3 = third parameter is optional and has to be an array
int varname4 = forth parameter has to be an integer and is optional

why is it [[, array varname3], int varname4] and not [, array varname3][,
int varname4]]:
because you cannot call php functionparameters by name. you can only call
them by order.
e.g.:
function("varname" => 'string', "varname2" => 1, "varname4" => 4);
is not valid. php doesn't provide the feature of calling functions by name.
you can work around that, but
it is not implemented directly.
so if you want to call the function but leaving the third parameter out, you
have to set a default value for
this parameter:
function('string', 1, array(), 4);
this works. so you have to pass the third parameter to be able to pass the
forth.
thats why it reads [[, array varname3], int varname4]]. the third is
required for the forth.
That's also why it is not possible to place optional parameters left and
required parameters
right:
int function([[, array varname3], int varname4]],string varname, mixed
varname2);
varname and varname2 are always required and we have to pass them to the
function.
But to be able to do that, we also have to pass varname3 and varname4.
function('string', 1);
will fail. it'll pass 'string' to varname3 and 1 to varname4, leaving
varname and varname2
unset.
But that all can be found in the manual. This was just a little help to get
started. :)
What i find additionally useful are the user contributed notes, which are
quite helpful sometimes.
Especially for newbies.

Regards Michael


"R" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
000801c20252$f859be40$0a6da8c0@lgwezec83s94bn">news:000801c20252$f859be40$0a6da8c0@lgwezec83s94bn...
> Hey,
> Welcome to PHP.
>
> I too am a newbie, I agree, php.net is too damn complex for a newbie, I
> would suggest starting off on webmonkey as its really easy and has some
> great examples for the beginner, then you can try to download the PHP
manual
> from php.net.
> Nearly everyone I spoke to swears by the manual but I am using "PHP black
> book" by peter moulding, coriolis and dreamtech publications, so far these
7
> chapters its really good, I do consult the manual a bit but am scared of
it
> :-)
>
> Hope that helped,
>
> -Ryan
>
>
>
>
>
> ----- Original Message -----
> From: "Darren Edwards" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, May 22, 2002 4:17 PM
> Subject: [PHP] Learning PHP
>
>
> > hi ppl i am learning PHP and was wondering if there is a good book or
web
> > site that i could learn ALOT from.  Not PHP.net coz the documentation is
> > just too complex there for a beginner.
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to