• 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,...
    0 Comments 0 Shares 4K Views 0 Reviews
  • 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...
    0 Comments 0 Shares 4K Views 0 Reviews
  • PHP - Concatenate Strings
    String Concatenation To concatenate, or combine, two strings you can use the . operator: ExampleGet your own PHP Server $x = "Hello"; $y = "World"; $z = $x . $y; echo $z; Try it Yourself » The result of the example above is HelloWorld, without a space between the two words. You can add a space character like this: Example $x = "Hello"; $y = "World"; $z =...
    0 Comments 0 Shares 3K Views 0 Reviews
  • PHP - Escape Characters
    Escape Character To insert characters that are illegal in a string, use an escape character. An escape character is a backslash \ followed by the character you want to insert. An example of an illegal character is a double quote inside a string that is surrounded by double quotes: ExampleGet your own PHP Server $x = "We are the so-called "Vikings" from the north."; Try it...
    0 Comments 0 Shares 4K Views 0 Reviews
  • PHP - Modify Strings
    PHP has a set of built-in functions that you can use to modify strings. Upper Case ExampleGet your own PHP Server The strtoupper() function returns the string in upper case: $x = "Hello World!"; echo strtoupper($x); Try it Yourself » Lower Case Example The strtolower() function returns the string in lower case: $x = "Hello World!"; echo...
    0 Comments 0 Shares 3K Views 0 Reviews
  • PHP - Slicing Strings
    Slicing You can return a range of characters by using the substr() function. Specify the start index and the number of characters you want to return. ExampleGet your own PHP Server Start the slice at index 6 and end the slice 5 positions later: $x = "Hello World!"; echo substr($x, 6, 5); Try it Yourself » Note The first character has index 0. Slice to the...
    Like
    1
    1 Comments 0 Shares 3K Views 0 Reviews
  • 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...
    0 Comments 0 Shares 4K Views 0 Reviews
  • 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,...
    0 Comments 0 Shares 4K Views 0 Reviews
  • 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...
    1 Comments 0 Shares 4K Views 0 Reviews
  • PHP Arrays
    An array stores multiple values in one single variable: ExampleGet your own PHP Server $cars = array("Volvo", "BMW", "Toyota"); Try it Yourself » What is an Array? An array is a special variable that can hold many values under a single name, and you can access the values by referring to an index number or name. PHP Array Types In PHP, there are three types of arrays:...
    0 Comments 0 Shares 2K Views 0 Reviews
  • 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 =...
    0 Comments 0 Shares 4K Views 0 Reviews
  • PHP Break
    The break statement can be used to jump out of different kind of loops. Break in For loop The break statement can be used to jump out of a for loop. ExampleGet your own PHP Server Jump out of the loop when $x is 4: for ($x = 0; $x < 10; $x++) { if ($x == 4) { break; } echo "The number is: $x <br>"; } Try it Yourself...
    0 Comments 0 Shares 2K Views 0 Reviews
More Results