function winFunction($name,$fir,$code,$nadd=false) { global $WEBGUI; if (!isset($WEBGUI['win'])) FatalError("Can't declare function/event without a window"); if (!isset($WEBGUI['win']['event'])) $WEBGUI['win']['event']=array(); if (!$nadd) { $c='var FUN=this.WGWin.WGEvent; var WIN=this.WGWin; var DATA=this.WGWin.WGData;'; $code="$c\n$code"; } addFunction($WEBGUI['win']['event'],$name,$fir,$code); }
<html> <head> <title>Writing PHP Function with Parameters</title> </head> <body> <?php function addFunction($num1, $num2) { $sum = $num1 + $num2; echo "Sum of the two numbers is : {$sum}"; } addFunction(10, 20); ?> </body> </html>
addOperation('mul', array('vec3', 'float'), array('type' => 'vec3', 'code' => array("MUL %1.xyz %2.xyz %3.x"))); addOperation('mul', array('vec3', 'vec3'), array('type' => 'vec3', 'code' => array("MUL %1.xyz %2.xyz %3.xyz"))); addOperation('mul', array('vec4', 'vec4'), array('type' => 'vec4', 'code' => array("MUL %1 %2 %3"))); addOperation('mul', array('mat3', 'vec3'), array('type' => 'vec3', 'code' => array("MUL %1.xyz %2[0].xyz %3.x", "MAD %1.xyz %2[1].xyz %3.y %1", "MAD %1.xyz %2[2].xyz %3.z %1"))); addOperation('mul', array('mat4', 'vec4'), array('type' => 'vec4', 'code' => array("MUL %1 %2[0] %3.x", "MAD %1 %2[1] %3.y %1", "MAD %1 %2[2] %3.z %1", "MAD %1 %2[3] %3.w %1"))); addOperation('mul', array('mat4', 'mat4'), array('type' => 'mat4', 'code' => array("MUL %1[0] %2[0] %3[0].x", "MAD %1[0] %2[1] %3[0].y %1[0]", "MAD %1[0] %2[2] %3[0].z %1[0]", "MAD %1[0] %2[3] %3[0].w %1[0]", "MUL %1[1] %2[0] %3[1].x", "MAD %1[1] %2[1] %3[1].y %1[1]", "MAD %1[1] %2[2] %3[1].z %1[1]", "MAD %1[1] %2[3] %3[1].w %1[1]", "MUL %1[2] %2[0] %3[2].x", "MAD %1[2] %2[1] %3[2].y %1[2]", "MAD %1[2] %2[2] %3[2].z %1[2]", "MAD %1[2] %2[3] %3[2].w %1[2]", "MUL %1[3] %2[0] %3[3].x", "MAD %1[3] %2[1] %3[3].y %1[3]", "MAD %1[3] %2[2] %3[3].z %1[3]", "MAD %1[3] %2[3] %3[3].w %1[3]"))); addOperation('sub', array('vec4', 'vec4'), array('type' => 'vec4', 'code' => array("SUB %1 %2 %3"))); addOperation('sub', array('vec3', 'vec3'), array('type' => 'vec3', 'code' => array("SUB %1.xyz %2.xyz %3.xyz"))); addFunction('dot', array('vec3', 'vec3'), array('type' => 'float', 'code' => array('DP3 %1 %2 %3'))); addFunction('dot', array('vec4', 'vec4'), array('type' => 'float', 'code' => array('DP4 %1 %2 %3'))); addFunction('max', array('float', 'float'), array('type' => 'float', 'code' => array('MAX %1.x %2.x %3.x'))); addFunction('normalize', array('vec3'), array('type' => 'vec3', 'code' => array('DP3 %1.x %2 %2', 'RSQ %1.x %1.x', 'MUL %1.xyz %2.xyz %1.x'))); addFunction('normalize', array('vec4'), array('type' => 'vec4', 'code' => array('DP4 %1.x %2 %2', 'RSQ %1.x %1.x', 'MUL %1 %2 %1.x'))); addFunction('pow', array('float', 'float'), array('type' => 'float', 'code' => array('POW %1.x %2.x %3.x'))); addFunction('reflect', array('vec3', 'vec3'), array('type' => 'vec3', 'code' => array('DP3 %1.x %3 %2', 'MUL %1.xyz %3 %1.x', 'MAD %1.xyz -%1 2.0 %2'))); addFunction('texture2D', array('sampler2D', 'vec2'), array('type' => 'vec4', 'code' => array('TEX %1 %3 %2 2D'))); ?> (function(glsl) { glsl.ir_operation_table = <?php echo json_encode($operation_table); ?> ; glsl.type.base = <?php echo json_encode($base_types); ?> ; function function_by_path(state, func, table, path) { var t, entry; for (t in table) {
<?php function addFunction($num1, $num2) { $sum = $num1 + $num2; return $sum; } $return_value = addFunction(10, 20); echo "Returned value from the function : {$return_value}"; ?>
<?php if (isset($_POST['btn'])) { $first_number = $_POST['firstNumber']; $last_number = $_POST['lastNumber']; $data = $_POST['btn']; switch ($data) { case '+': $calculation = addFunction($first_number, $last_number); break; case '-': $calculation = subFunction($first_number, $last_number); break; case '*': $calculation = multiFunction($first_number, $last_number); break; case '/': if ($last_number == 0) { echo 'Sorry we are not able to calculate something that are divided by ZERO'; } else { $calculation = divFunction($first_number, $last_number); } break; case '%': $calculation = modFunction($first_number, $last_number); break; default: echo 'Sorry something unusal happened'; break; } }
function ProcessFunctionAddEdit() { $errors = ""; if (empty($_POST["Name"])) { $errors .= "<li>Error, field \"Name\" is blank.</li>"; } if ($errors == "") { $FunctionID = $_POST["FunctionID"]; $name = $_POST["Name"]; $desc = $_POST["Description"]; if (empty($FunctionID)) { // No FunctionID means we are processing an ADD $FunctionID = addFunction($name, $desc); } else { updateFunction($FunctionID, $name, $desc); } $results = getAllFunctions(); include '../security/manage_functions_form.php'; } else { displayError($errors); } }