Other
    PHP - $_SERVER
    $_SERVER $_SERVER is a PHP super global variable which holds information about headers, paths, and script locations. The example below shows how to use some of the elements in $_SERVER: ExampleGet your own PHP Server echo $_SERVER['PHP_SELF']; echo $_SERVER['SERVER_NAME']; echo $_SERVER['HTTP_HOST']; echo $_SERVER['HTTP_REFERER']; echo $_SERVER['HTTP_USER_AGENT']; echo $_SERVER['SCRIPT_NAME']; Try it Yourself » The following table lists the most important...
    By PHP Tutorial 2024-05-17 08:08:50 0 4K
    Other
    PHP $GLOBALS
    $GLOBALS is an array that contains all global variables. Global Variables Global variables are variables that can be accessed from any scope. Variables of the outer most scope are automatically global variables, and can be used by any scope, e.g. inside a function. To use a global variable inside a function you have to either define them as global with the global keyword, or refer to them by using the $GLOBALS syntax. ExampleGet your own PHP Server Refer to...
    By PHP Tutorial 2024-05-17 08:08:27 0 4K
    Other
    PHP Global Variables - Superglobals
    Superglobals were introduced in PHP 4.1.0, and are built-in variables that are always available in all scopes. PHP Global Variables - Superglobals Some predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. The PHP superglobal variables are: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION The...
    By PHP Tutorial 2024-05-17 08:08:10 0 3K
    Other
    PHP Array Functions
    PHP Array Functions PHP has a set of built-in functions that you can use on arrays. Function Description array() Creates an array array_change_key_case() Changes all keys in an array to lowercase or uppercase array_chunk() Splits an array into chunks of arrays array_column() Returns the values from a single column in the input array array_combine() Creates an array by using the elements from one "keys" array and one "values" array...
    By PHP Tutorial 2024-05-17 08:07:42 1 3K
    Other
    PHP Multidimensional Arrays
    In the previous pages, we have described arrays that are a single list of key/value pairs. However, sometimes you want to store values with more than one key. For this, we have multidimensional arrays. PHP - Multidimensional Arrays A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people. The dimension of...
    By PHP Tutorial 2024-05-17 08:07:20 0 3K
    Other
    PHP Sorting Arrays
    The elements in an array can be sorted in alphabetical or numerical order, descending or ascending. PHP - Sort Functions For Arrays In this chapter, we will go through the following PHP array sort functions: sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative arrays in ascending order, according to the value ksort() - sort associative arrays in ascending order, according to the key arsort() - sort...
    By PHP Tutorial 2024-05-17 08:06:46 0 3K
    Other
    PHP Delete Array Items
    Remove Array Item To remove an existing item from an array, you can use the array_splice() function. With the array_splice() function you specify the index (where to start) and how many items you want to delete. ExampleGet your own PHP Server Remove the second item: $cars = array("Volvo", "BMW", "Toyota"); array_splice($cars, 1, 1); Try it Yourself » After the deletion, the array gets reindexed automtically, starting at index 0. Using the unset...
    By PHP Tutorial 2024-05-17 08:06:22 0 3K
    Other
    PHP Add Array Items
    Add Array Item To add items to an existing array, you can use the bracket [] syntax. ExampleGet your own PHP Server Add one more item to the fruits array: $fruits = array("Apple", "Banana", "Cherry"); $fruits[] = "Orange"; Try it Yourself » Associative Arrays To add items to an associative array, or key/value array, use brackets [] for the key, and assign value with the = operator. Example Add one item to the car array:...
    By PHP Tutorial 2024-05-17 08:06:05 0 3K
    Other
    PHP Update Array Items
    Update Array Item To update an existing array item, you can refer to the index number for indexed arrays, and the key name for associative arrays. ExampleGet your own PHP Server Change the second array item from "BMW" to "Ford": $cars = array("Volvo", "BMW", "Toyota"); $cars[1] = "Ford"; Try it Yourself » Note: The first item has index 0. To update items from an associative array, use the key name: Example Update the year to 2024: $cars = array("brand"...
    By PHP Tutorial 2024-05-17 08:02:49 0 3K
    Other
    PHP Access Arrays
    Access Array Item To access an array item, you can refer to the index number for indexed arrays, and the key name for associative arrays. ExampleGet your own PHP Server Access an item by referring to its index number: $cars = array("Volvo", "BMW", "Toyota"); echo $cars[2]; Try it Yourself » Note: The first item has index 0. To access items from an associative array, use the key name: Example Access an item by referring to its key name: $cars =...
    By PHP Tutorial 2024-05-17 08:02:32 0 4K
    Other
    PHP Create Arrays
    Create Array You can create arrays by using the array() function: ExampleGet your own PHP Server $cars = array("Volvo", "BMW", "Toyota"); Try it Yourself » You can also use a shorter syntax by using the [] brackets: Example $cars = ["Volvo", "BMW", "Toyota"]; Try it Yourself » Multiple Lines Line breaks are not important, so an array declaration can span multiple lines: Example $cars = [ "Volvo", "BMW", "Toyota" ]; Try it...
    By PHP Tutorial 2024-05-17 08:01:55 0 3K
    Other
    PHP Associative Arrays
    PHP Associative Arrays Associative arrays are arrays that use named keys that you assign to them. ExampleGet your own PHP Server $car = array("brand"=>"Ford", "model"=>"Mustang", "year"=>1964); var_dump($car); Try it Yourself » Access Associative Arrays To access an array item you can refer to the key name. Example Display the model of the car: $car = array("brand"=>"Ford", "model"=>"Mustang", "year"=>1964); echo $car["model"]; Try it Yourself...
    By PHP Tutorial 2024-05-17 08:01:14 0 4K
More Blogs
Read More
Other
PHP do while Loop
The do...while loop - Loops through a block of code once, and then repeats the loop as...
By PHP Tutorial 2024-05-17 07:49:22 0 2K
Other
PHP Casting
Sometimes you need to change a variable from one data type into another, and sometimes you want a...
By PHP Tutorial 2024-05-17 07:38:02 0 2K
Other
PHP Shorthand if Statements
Short Hand If To write shorter code, you can write if statements on one line....
By PHP Tutorial 2024-05-17 07:47:03 0 2K
Other
PHP if Operators
Comparison Operators If statements usually contain conditions that compare two values....
By PHP Tutorial 2024-05-17 07:45:46 0 2K
Other
PHP Create Arrays
Create Array You can create arrays by using the array() function: ExampleGet your...
By PHP Tutorial 2024-05-17 08:01:55 0 3K