Breaking an include
When you want to omit the remaining of a loop you write a break statement.
Is there something that you can write to omit the remaining of an includ开发者_开发百科ed file (but not terminate the rest of the app like when using die
or exit
)?
You can use a return
statement to exit an included file, and optionally return a value.
Example:
<?php
// file1.php:
$value = include('file2.php');
echo $value;
Which includes:
<?php
// file2.php:
if($_REQUEST['something'] == 'something else')
return 'Something else';
//do some stuff if _REQUEST['something'] != 'something else'
return 'something';
Obviously a useless example, but, it demonstrates the use of return
to eit an include()
ed file.
you could split your include into two separate files, then require the two as necessary instead of just one, or possibly just require the one and have that one require the second as necessary.
精彩评论