require_once "functions.php"; in each place. A line is added at the very top of that shared file, outside any function, meant to run once per page. Instead, on some pages, it visibly runs twice. require_once is supposed to prevent loading the same file twice. Why would it still run that line's code twice on one page?require_once prevents the exact same path string from being loaded twice within one request. It compares paths as text, not file contents. If that file gets pulled in from two different-looking paths that both happen to resolve to the same actual file, such as a relative path from one folder and a slightly different relative or absolute path from another, PHP's tracking can treat them as two distinct files, requiring each path once and running that file's top-level code twice in total.require and include both pull the contents of another PHP file into the current one, at the exact spot the line appears, as if that file's contents were typed directly into that location.require stops the entire script immediately, with a fatal error, if the file cannot be found. include only produces a warning in that situation and lets the rest of the script keep running without whatever that file would have defined._once, as in require_once or include_once, tells PHP to skip loading that exact path again if it has already been loaded earlier in the same request, which matters most for files that define functions or classes.require or include line is resolved relative to the file that line is actually written in, not relative to whichever address a visitor originally requested.format_price(), is written exactly once, inside a file commonly named something like functions.php. The second block, inside a different file such as index.php, never repeats that function's own code. It only calls it by name after pulling it in with require_once.require_once "functions.php" checks whether that exact path has already been loaded earlier in this same request. If some other part of the page already required that same path string before this line ran, this second require_once does nothing at all, and no error occurs either way.number_format( $amount, 2 ) is a built-in function, not one this program wrote. It rounds and formats a number to exactly 2 digits after the decimal point and adds thousands separators, which is why 49.5 becomes the text "49.50", not "49.5".$total is created in the second file, after functions.php has already been pulled in, so by the time $total = 49.5; runs, format_price() already exists and is ready to be called. Calling it before that require_once line would fail, because the function would not exist yet.require_once stops the page entirely with a fatal error if functions.php cannot be found at all at the given path. include_once, used the same way, only produces a warning and lets the rest of the page keep running without that file's functions defined.require_once's duplicate-protection compares the resolved path strings, not whether the underlying file is identical.require and require_once both produce a fatal error and stop the rest of the script from running at all, the moment the file cannot be found. A visitor sees a broken or blank page rather than a page merely missing one feature, which is why require is generally preferred over include for anything the rest of the page genuinely cannot work without.require or include does not get a separate, protected set of variables. If functions.php happened to contain a line like $total = 0; outside any function, that line would overwrite the including file's own $total the moment it ran, exactly as if both lines were typed into one file.format_price(), the second one to load causes a fatal cannot-redeclare error. This is one of the most common reasons require_once, rather than plain require, matters once a project grows past a single shared file.require "functions.php" is resolved relative to the file containing that exact line, not relative to whichever address the visitor originally requested. Moving a file into a subfolder without updating its require paths is a common reason an otherwise unchanged file suddenly cannot find something it required successfully for months.require_once, not plain require, for any file defining functions or classes that might get pulled in from more than one place. Second, does a relative path inside a required file assume one specific calling location that might not always be true. Third, does an included file avoid defining a top-level variable name, such as $total, that could collide with one already in scope in the file that includes it.$total = 0; line directly inside functions.php, outside any function, then check whether it changes the $total value already set in the including file.Welcome back to Jit4All