calling a function from another file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

calling a function from another file

Post by stevestark5000 »

lets say i have 3 functions in file b. In file a i would like to call the first function from file b. can this be done. if so can i have an example please.
jim.barrett
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2011 5:47 am

Re: calling a function from another file

Post by jim.barrett »

This is done by including the file that contains the functions on the page where you want to call the functions.

Code: Select all

<?php
   include("fileB.php");
?>
...add a line like this to fileA.php and you can call any function from the other file. Of course, your include has to happen before the function can be called (closer to the top of the page).

Is this what you were looking for?
stevestark5000
Forum Commoner
Posts: 61
Joined: Thu Jan 27, 2011 12:08 am

Re: calling a function from another file

Post by stevestark5000 »

yes just what i was looking for. php seems easy to learn. thank you.
Post Reply