$total inside itself, using the exact same name as a $total that already exists outside the function, one the rest of the page depends on. After the function runs, the outer $total is completely unaffected by anything that happened inside. Why would using the very same name not connect the two at all?$total variables are not connected, unless the function specifically receives the outer one as a parameter and returns a new value, or the function uses the global keyword to reach outside its own scope on purpose.function followed by a name and a list of parameters in parentheses, and can then be called by that name as many times as needed, from anywhere later in the same file.return sends a single value back out of a function to wherever it was called from. A function with no return line at all produces null as its result, even if the function's body did other useful work along the way.function f( $percent = 10 ). That default is only ever used when a call leaves that argument out entirely.$percent = 10 inside the parameter list means a call like apply_discount( $total ), with only one argument, still works, using 10 automatically. The second call, apply_discount( $total, 25 ), supplies its own value instead, overriding that default just for that one call.$discount, created inside the function, never exists anywhere outside it. Once the function returns, that name is gone completely, and the next line of the program could reuse $discount for something else entirely with no connection to this one.apply_discount( $total ) does not hand the function the variable $total itself. It hands the function a copy of whatever value $total held at that exact moment. Changes the function makes to its own local $amount parameter never reach the outer $total at all, only the returned value does.$total = apply_discount( $total ) deliberately reuses the same name on both sides. This is not the function changing $total. It is the outer code choosing to replace its own $total with whatever value comes back from the call, which only looks like the same variable being updated in place.apply_discount() twice in a row, with the first call's result feeding into the second, chains a 10 percent discount and then a 25 percent discount on top of the already-discounted number, not 35 percent off the original amount.$discount, created inside apply_discount(), produces an undefined-variable warning if read anywhere outside the function, even on the very next line after calling it. This strict separation, called scope, is what lets two different functions both use a name like $discount internally without ever colliding.$total into apply_discount( $amount, ... ) gives the function its own separate copy, named $amount, to work with. Reassigning $amount inside the function, even many times, never changes the value sitting in the outer $total variable at all.apply_discount( $total, 25 ) ignores the default of 10 completely, because a value was actually supplied for that position. The default in the function's own definition only ever takes effect when that argument is left out of the call entirely.global $total; as the first line inside a function connects that function's $total directly to the outer one, instead of creating a separate local copy. This is the one deliberate exception to the usual rule, and it is rarely used in well-organized PHP, precisely because it makes a function's behavior depend on something its own parameter list does not show.global to reach a variable, when accepting a parameter and returning a value would do the exact same job more clearly. Second, if a parameter has a default value, does any actual call site ever rely on that default, or does every call supply its own value anyway, making the default dead code. Third, when two calculations are meant to be chained, does the function's logic correctly compound on the previous result, rather than always recalculating from one fixed starting number.apply_discount( $total, 0 ) and confirm the returned value equals the original $total exactly, to check that a 0 percent discount really changes nothing.$percent entirely, then call apply_discount( $total ) with only one argument as before, and read the resulting error message closely.apply_tax( $amount, $percent = 8 ), shaped the same way as apply_discount(), and chain it after a call to apply_discount().global $log = []; line outside the function, and a line inside apply_discount() that appends to $log using global $log;, to see the global keyword used for a purpose other than changing $total itself.apply_discount( $total, 25 ) is called before apply_discount( $total ) instead of after, swapping the two calls' order, then run it to check.function f( $a = 1, $b ), which PHP either rejects or handles in a confusing, easy-to-misuse way. Required parameters belong before parameters with defaults, not after.return inside a function entirely, then trying to use the function's result directly, such as echo apply_discount( $total );, and getting nothing printed at all, because a function with no return produces null.apply_discount( 25, $total ) silently swaps which number is treated as the amount and which is treated as the percent, since PHP matches arguments to parameters by position, not by guessing intent.Welcome back to Jit4All