🌐
W3Schools
w3schools.com › php › php_syntax.asp
PHP Syntax
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php › func_array_end.asp
PHP end() Function
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php › func_misc_exit.asp
PHP exit() Function
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php › php_intro.asp
PHP Introduction
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.sinsixx.com › php › func_array_end.asp@output=print.htm
PHP end() Function - SinSiXX - W3Schools
From http://www.w3schools.com (Copyright Refsnes Data) Complete PHP Array Reference · The end() function moves the internal pointer to, and outputs, the last element in the array. This function returns the value of the last element in the array on success. The output of the code above will ...
🌐
W3Schools
w3schools.com › php › php_functions.asp
PHP Functions
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
campus.w3schools.com › collections › career paths › learn back end development with php
Learn Back End development with PHP — W3Schools.com
Learn Back End development with PHP
Learn backend development with SQL, MySQL, and PHP. This course gets you ready for backend development jobs in different fields. Earn 4 certifications – exams included, and boost your resume. Master Back End development – gain the skills needed to build and manage robust backend systems. Hero sub included – get one year of the Hero plan. Get access to premium learning content – challenges, practice tests, and more.  No experience required – perfect for beginners. Learn at your own pace – flexible, self-paced learning. Become a Certified Back End developer with W3Schools.
Price   $190.00
🌐
W3Schools
w3schools.com › php › keyword_endforeach.asp
PHP endforeach Keyword
The endforeach keyword is used to close the code block of a foreach loop which was started using the foreach(...): syntax. The foreach keyword. Read more about for loops in our PHP foreach Loop Tutorial.
🌐
W3Schools
w3schools.com › php › keyword_endif.asp
PHP endif Keyword
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php › php_looping_break.asp
PHP Break Statement
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
Find elsewhere
🌐
W3Schools
w3schools.in › php › syntax
PHP Syntax - W3schools
echo is a command in PHP for writing output data to the browser, and at the end of each PHP statement, we are required to write a (semicolon) as you see in the below example code.
🌐
W3Schools
w3schools.com › php › php_examples.asp
PHP Examples
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php
PHP Tutorial
Most chapters in this tutorial end with exercises where you can check your knowledge. ... Learn by examples! This tutorial supplements all explanations with clarifying examples. ... Learn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about PHP. Start PHP Quiz! View your completed tutorials, exercises, and quizzes ... Note: This is an optional feature. You can study at W3Schools without creating an account.
Top answer
1 of 7
5

$_POST is a reserved "superglobal" variable, meaning it is:

  1. Created automatically by the server and
  2. Available everywhere.

It automatically contains all data sent to the server with an HTTP POST request. Technically, it is (from the manual):

An associative array of variables passed to the current script via the HTTP POST method.

So if you have a form with name and email input fields, $_POST is an array with keys named name and email, which contain the data submitted by the user. You could access these with $_POST['name'] and $_POST['email'], respectively.

There are several other superglobal variables, namely:

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
  • $_SESSION
  • $_REQUEST
  • $_ENV

You can learn much more about this by reading the manual entry on $_POST or the manual entry on superglobal variables.

To answer your other questions:

trim() removes white space (like spaces, tabs, and new lines) from the beginning and end of a string. For example, trim(' foo ') produces just foo without the spaces. You can also make it remove other characters. Say you have xxxfooxxx. trim('xxxfooxxx', 'x') will take away the xs and leave you just foo.

stripslashes() removes slashes from a string that has escaped characters. For example (from the manual):

$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);

htmlspecialchars() turns special characters into HTML "entities." Specifically, it changes the following:

  • & (ampersand) becomes &
  • " (double quote) becomes " when ENT_NOQUOTES is not set.
  • ' (single quote) becomes ' (or ') only when ENT_QUOTES is set.
  • < (less than) becomes &lt;
  • > (greater than) becomes &gt;
2 of 7
3

$_POST is part of the "superglobal" family.


I quote from the manual:

Superglobals are built-in variables that are always available in all scopes.

Several predefined variables in PHP are "superglobals", which means they are available in all scopes throughout a script. There is no need to do global $variable; to access them within functions or methods.

These superglobal variables are:

  • $GLOBALS
  • $_SERVER
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
  • $_SESSION
  • $_REQUEST
  • $_ENV

Then in your PHP handler, the form's element would be accessed in this fashion:

A basic example:

<?php
$name = $_POST['name']; // taken from <input type="text" name="name">
echo $name;             // would echo the entered name from the form.

Something important to remember:

When using superglobals, they must be in uppercase letters.

$_post and $_Post for example are considered invalid. Use $_POST < exactly like this etc.

Some have/do that mistake, and will not work if not using the proper syntax (uppercase).

Also, the underscore _ between the $ and the superglobal name POST for example, is also required. $POST < being invalid. Again, use $_POST - $_GET - $_REQUEST etc.


About certain functions and predefined variables

  1. trim()
    • Strips whitespace (or other characters) from the beginning and end of a string
  2. stripslashes()
    • Un-quotes a quoted string
  3. htmlspecialchars()
    • Converts special characters to HTML entities
  4. $_SERVER["PHP_SELF"]
    • Executes from the same location of the originating script. Using action="" does the same job.
  5. $_SERVER["REQUEST_METHOD"]
    • Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'

Eventual/potential database work

Should you later want to adventure yourself in databases, you could use these variables as shown below, using mysqli_* as an example:

<?php
// DB connection credentials
$name = mysqli_real_escape_string($con,$_POST['name']);
// rest of DB query
//

$con being something to the effect of:

$con = new mysqli("host","username", "password", "database");
🌐
W3Schools
w3schools.com › php › php_exercises.asp
PHP Exercises
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
W3Schools
w3schools.com › php › php_ref_overview.asp
PHP Reference
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
Tutorial Republic
tutorialrepublic.com › php-reference › php-end-function.php
PHP end() Function - Tutorial Republic
Here're some more examples showing how end() function actually works: The following example demonstrates how to get the last value from an associative array: ... <?php // Sample array $alphabets = array("a"=>"apple", "b"=>"ball", "c"=>"cat", "d"=>"dog"); // Getting the last element's value echo end($alphabets); // Prints: dog // Getting the last element's key echo key($alphabets); // Prints: d ?>
🌐
W3Schools
w3schools.com › PhP › php_looping.asp
PHP Loops
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
W3Schools
w3schoolsua.github.io › php › php_examples_en.html
PHP Examples. Lessons for beginners. W3Schools in English
$GLOBAL - Used to access global variables from anywhere in the PHP script $_SERVER - Holds information about headers, paths, and script locations $_REQUEST - Used to collect data after submitting an HTML form $_POST - Used to collect form data after submitting an HTML form. Also used to pass variables $_GET - Collect data sent in the URL ... Do a case-insensitive search for 'w3schools' in a string Do a case-insensitive count of the number of occurrences of 'ain' in a string Replace 'Microsoft' with 'W3Schools' in a string