Skip to main content

PRACTICAL 7_2

PRACTICAL 2:



Study and demonstrate php syntax, data type, variable, function, array, superglobal variable and form.

THEORY
In this web page, we will study and implement basics syntax of php.

IMPORTANT TAGS & ATTRIBUTES:


Basic Syntax: When PHP parses a file, it looks for opening and closing tags, which are <?php and ?> which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser.
            E.x. <?php        content                        ?>

Data types: Although variables are not declared to be type-specific in PHP, PHP still has a common set of data types: Boolean, integer, float, string, array, object, resource, NULL
Determining the current type of a variable: A series of type-testing functions exist to determine the current type of variables:
gettype(varname): returns type name, such as 'string'
similarly, is_int()  is_integer()  is_long()  is_null()  is_numeric() is_object()  is_real()  is_string()  is_scalar()  is_bool() empty()  isset()
Variables: Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
             E.x. $var = "Bob";
        $Var = "Joe";  // different variable

Function: A function may be defined using syntax such as the following:
            E.x.
<?php
function foo($arg_1, $arg_2, /* ..., */ $arg_n)
{
    echo "Example function.\n";
    return $retval;
}
?>
Any valid PHP code may appear inside a function, even other functions and class definitions.
Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Array: An array can be created using the array() language construct. It takes any number of commaseparated key => value pairs as arguments.
array(     key  => value,     key2 => value2,     key3 => value3,
    ...
)
The comma after the last array element is optional and can be omitted. This is usually done for singleline arrays, i.e. array(1, 2) is preferred over array(1, 2, ). For multi-line arrays on the other hand the trailing comma is commonly used, as it allows easier addition of new elements at the end.

Superglobal: The $GLOBALS array is an associative array with the name of the global variable being the key and the contents of that variable being the value of the array element. Notice how $GLOBALS exists in any scope, this is because $GLOBALS is a superglobal. Here's an example demonstrating the power of superglobals:
            E.x.
<?php
function test_superglobal()
{


SCREENSHOT WEB PAGE:











NAME:AYUSH SINGLA
ID:18CE122


Comments