Hi everyone, I'll try to be brief and to the point - i'm starting to incorporate include() into my php pages to clean up the code but seem to run into problems when trying to call functions that are included in different files. I've been trying to do some research on function scope and please excuse my ignorance, but is this at all possible? For example we have two files:
File 1: function.inc
<?php function test() {
switch ( $var ) {
case ( $var < 130 ):
echo " A " ;
break;
case ( $var < 480 ):
echo " B ";
break;
case ( $var < 1230 ):
echo " C ";
break;
case ( $var < 1830 ):
echo " D ";
break;
case ( $var < 1831 ):
echo " E ";
break;
}
}
?>
And to clean up another page, in another file, index.php - I'd like to be able to call the function test() ...
File 2: index.php
<head>
<title>Testin g Page</title>
<?php include 'function.inc'; ?>
</head>
<body>
<?php test(); ?>
</body>
</html>
Could anyone please help me? And if this isn't possible, is there any kind of workaround for these kinds of things? Thanks in advance.
Nick
File 1: function.inc
<?php function test() {
switch ( $var ) {
case ( $var < 130 ):
echo " A " ;
break;
case ( $var < 480 ):
echo " B ";
break;
case ( $var < 1230 ):
echo " C ";
break;
case ( $var < 1830 ):
echo " D ";
break;
case ( $var < 1831 ):
echo " E ";
break;
}
}
?>
And to clean up another page, in another file, index.php - I'd like to be able to call the function test() ...
File 2: index.php
<head>
<title>Testin g Page</title>
<?php include 'function.inc'; ?>
</head>
<body>
<?php test(); ?>
</body>
</html>
Could anyone please help me? And if this isn't possible, is there any kind of workaround for these kinds of things? Thanks in advance.
Nick
Comment