Exforsys
+ Reply to Thread
Results 1 to 2 of 2

How can define a function in a PHP?

This is a discussion on How can define a function in a PHP? within the PHP forums, part of the Programming Talk category; Today PHP is the most useful language for development but how can i define a function in PHP? If you ...

  1. #1
    andrepitt77 Guest

    How can define a function in a PHP?

    Today PHP is the most useful language for development but how can i define a function in PHP? If you know than please reply me.


  2. #2
    lokeshm is offline Member Array
    Join Date
    Apr 2005
    Answers
    83
    andrepitt77

    Generally we create function.
    I am not sure if you are referring to creating function or you are specifically asking about Defining a function.

    We create function in PHP as shown here below

    function somename($optional_arg1, $optional_arg2) {
    //Do something
    $result = $optional_arg1 + $optional_arg2;
    return ($result);
    }


    PHP also has DEFINE function which is used to define a constant.

    Example
    define(DB_NAME,"testdb_blogs");

    Once a constant is defined, it can be used anywhere.
    Generally define function is used in config files from where admin can set / reset various constant values.

    Regards,
    Lokesh M.


Latest Article

Network Security Risk Assessment and Measurement

Read More...