Check if a file exists and use return() to return a string variable in PHP

I have two files: I need to inclide a.php in b.php then call the a function to return a string variable and print it.
a.php:
function CheckExist($file) {
$response;
if (file_exists($file) {
$response = "File Extisted";
} else {
$response = "File Not Existed";
}
return $response;
}
b.php
// Some code to include a.php and call the function to get the string variable
print($response);
Answer
Solution:
I understand you want to include file a.php in b.php and be able to use the function in a.php.
In PHP, you can include files using require_once, require, include and include_once statements which you should have probably known about before asking this question.
To suggest a solution while you read from the links I have provided, you can use any of the above functions to include your file a.php, call the function and save the return value in a variable and print it out:
b.php
require("a.php");
$response = CheckExists("a-sample-file.txt");
print($response);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.