Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call php function from another file?

Tags:

php

I want to call my custom php function from my index.php, but the function is located in another file. Ho to do that ?

Example :

index.php :

<?php

myCustomFunction();

?>

function.php

<?php

function myCustomFunction(){
//some codes
}

?>

Thank you.

like image 750
brown26 Avatar asked Dec 19 '22 09:12

brown26


1 Answers

Change index.php as follows:

<?php
  include "function.php";
  myCustomFunction();
?>

(this is based on the assumption that both files are in the same directory, otherwise you have to add the filepath in the include line)

like image 65
Johannes Avatar answered Jan 04 '23 15:01

Johannes