how to use use a function call in a php file ?

Posted on 2007-07-24
Last Modified: 2007-07-24

In my php file test.php, there are two places which used exactly the same block of code. Is that possible that I can change that block of code into a functionin in test.php. I can call this function when I need to use it ? A sample example will be very helpful. :)

Thanks very much for your reply,
Question by:lilyyan
    LVL 24

    Accepted Solution

    PHP functions are very simple to use. Here is an example:


    $sum1 = addNumbers(1, 3);

    $sum2 = addNumbers(5, 7);

    function addNumbers($value1, $value2)
       return $value1 + $value2;


    Author Comment

    Hi, thanks for your pormpt reply. i will have a try now and get back soon.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now