如何从另一个页面设置和调用php指令

如何从另一个页面设置和调用php指令,php,Php,在calculate.php中,我有以下代码: //recovery the variables from an html form $FirstNumber=$_POST['FirstNumber']; $SecondNumber=$_POST['SecondNumber']; $Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'. //Now I have to call specific instructions

在calculate.php中,我有以下代码:

//recovery the variables from an html form
$FirstNumber=$_POST['FirstNumber'];
$SecondNumber=$_POST['SecondNumber'];
$Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.
//Now I have to call specific instructions in instructions.php (Which is the one for operations) sending to it my variables
//Now I have to recovery $result from instructions.php
echo "Result: $result";
假设在instructions.php中,我有:

页面需要了解它必须执行的指令,在这种情况下是来自操作部门的指令

//-----Operations-------------------------------------------------------------------------
//recovery variables from calculate.php
//Tottaly doesen't know how
switch ($Operation){
case "+":
$result=$FirstNumber+$SecondNumber;
//Now I send the result in calculate.php
break;
//repeat for all the possible cases
}
//------Strings---------------------------------------------------------------------------
$control=$String;
if ($checked){
$control=$String."_Controlled";
//I have to return $control
}else {
$checked=true;
 $control=$String."_Controlled";
//return $control
}
//------Other instructions for other requests---------------------------------------------
那么,如何从另一个php页面定义和调用一系列指令呢

请不要用meta refresh方法回答我,这不是我要找的,也不是我要问的。

您可以选择使用或方法将包含所有功能的页面包含到当前页面中

现在,您可以使用在post方法中获取变量的页面,并在同一页面的起点处包含另一个页面,例如

如果您在post方法中获得calculate.php上的变量,那么 可以在calculate.php顶部使用require

<?php
    require('path/to/operation.php');

    //recovery the variables from an html form
    $FirstNumber=$_POST['FirstNumber'];
    $SecondNumber=$_POST['SecondNumber'];
    $Operation=$_POST['Operation']; //this can be '+', '-', '*', '/'.

    echo "Result: ". calculate($Operation, $FirstNumber, $SecondNumber);
?>



//In your Operation.php it should be like function, and you can call that function using calculate.php to get the result.

function calculate($Operation, $FirstNumber, $SecondNumber)
    switch ($Operation){
        case "+":
            $result=$FirstNumber+$SecondNumber;
            return $result;
        break;
    }
    $control=$String;
    if ($checked){
        $control=$String."_Controlled";
        //I have to return $control
    }else {
        $checked=true;
        $control=$String."_Controlled";
        //return $control
    }
}
您可以使用include文件并在operation.php中调用变量

例如:

<?php
   include('path/to/operation.php');
   $result=$FirstNumber+$SecondNumber;
  echo $result;
?>

只需在calculate.phpSo顶部使用require_once“operations.php”,我就必须调用整个页面?一种方法是将变量放入$_会话,但在另一个页面中使用值的最佳方法是包含第一个页面:“include'page.php'@halojoy”,因此,我将需要的页面包含在使用它的页面顶部,但是我如何发送变量,如何得到结果,最重要的是,我如何告诉calculate.php何时调用和使用operations.php?如果在第一页有3个变量,并且在第二页包含第一页,那么变量在第二页,但是,当使用operation.php的指令时,如何选择?那么如何从中得到结果呢?如果你想将所有函数分离到一个文件中,而该文件是operation.php,而不是在calculate.php上编写函数,你可以使用这个场景。斯普里,我听不懂你说的,你是在替我说外星人。谢谢,伙计,这就是我要找的