php require
// Include a file, if it can't be found: continue.
<?php
include 'mainfile.php';
?>
// Alternatively: Require a file to be imported or quit if it can't be found
<?php
require 'requiredfile.php';
?>
3.75
8
// Require a file to be imported or quit if it can't be found
<?php
require 'somefile.php';
?>
// Alternatively: Include a file, if it can't be found: continue.
<?php
include 'vars.php';
?>
Thank you!
8
0
4.5
2
// Require a file to be imported or quit if it can't be found
<?php
require 'requiredfile.php';
?>
Thank you!
2
0
4
8
# return.php
<?php
$var = 'PHP';
return $var;
?>
# noreturn.php
<?php
$var = 'PHP';
?>
# testreturns.php
<?php
$foo = include 'return.php';
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
?>
//$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return within the included file while the other does not. If the file can't be included, false is returned and E_WARNING is issued.
Thank you!
8
0
Are there any code examples left?
New code examples in category PHP