1

i have this code

if (isset($title) && ($title !== null))

And tried this one too

if (isset($title) && ($title === true))

but this code dont work becouse it dont check if variable exist and do code in if. I want to check if variable exist in another file how can i do that ?

3
  • Have you tried moving the if-clause into the other file in which you want to run the check? How did it work? Was that the solution or why wasn't that the solution? Commented Jun 18, 2017 at 7:40
  • If the other file is not called in any way by the current page/script then any variables you are expecting to find will not have been instantiated. If the other file is called in some way then it should be before you attempt to test for the existence of the variable Commented Jun 18, 2017 at 7:45
  • first is include if file exists and in this if is this code. Commented Jun 18, 2017 at 7:49

1 Answer 1

2

Use include or require before the if condition and then try to print if exist:

Example::

<?php 
require 'demo.php'; //suppose in this file $title=' Hello world';

if (isset($title) && ($title !== null)&& ($title !== '') ){

echo '$title'; // echo the title here

}

?>
Sign up to request clarification or add additional context in comments.

1 Comment

Your Welcome Bro... :) Happy To Help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.