Summary


Functions let you break up your code into manageable chunks, which is great for limiting the scope of possible conflicts between variables. You can pass data to functions and have functions return values as well. The whole idea here is to compartmentalize what's going on in your scripts so that you're dealing with only a dozen or so lines of code at a time instead of thousands. Here's a summary of the salient points in this chapter:

  • You use the function statement to create a function.

  • You call a function simply by using its name.

  • You pass data to functions using an argument list enclosed in parentheses after the function's name. Inside the function's body, you can access the value of the arguments you've passed to the function using the name you gave each argument in the argument list.

  • You can pass arrays to functions with no extra work.

  • If you give an argument a default value, that value will be used if you don't supply a value for the argument when calling the associated function.

  • If you prefix a function argument with &, that argument is passed by reference, which gives you direct access to the argument's data.

  • Using the func_get_args() function, you can create functions with variable-length argument lists.

  • Declaring variables as static inside a function preserves their value between function calls.



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net