PHP

// $var1--;
    // $var1++;
    // echo $var2++;  //Will print var2 then increase its value
    // echo ++$var2; //Will increase then print
    // echo var_dump($var1 == $var2);  // bool(false)
    // echo '<h1>Yashovardhan Singh Rajput<h2>';
<?php 
// PHP statements end with a semicolon (;).
// In PHP, NO keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are case-sensitive. All variable names are case-sensitive!
// In PHP, a variable starts with the $ sign, followed by the name of the variable, $txt = "Hello world!";
// A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function. The global keyword is used to access a global variable from within a function.
// PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly.
// If we want a local variable NOT to be deleted use static keyword.
// && = and, || = or, xor(TRUE if either $a or $b is TRUE, but not both.), ! = not
// $myVar = true and true;
// $myVar = (true xor true);
// echo var_dump($myVar);  ->  false
// echo strlen('yashovardhan');  // length of string
// str_repeat($name, 5)
// trim(str) = trim from every side.
// strtolower(str); and strtoupper(str);
// ltrim(str); strim left side
// rtrim(str); // use pre tag to display string as it is.
// echo str_word_count('hello world');  // number of words
echo strrev('yash'); // -> reverses a string
// echo strpos('yashovardhan', 'ovar');searches for a specific text within a string(returns index)
// echo str_replace('world', 'yasho', 'hello world');
// $x = 5985;  -> to check if a var is a number use is_int($x);
// var_dump(is_int($x));
// is_finite(), is_infinite(), is_float(), is_nan()[not a number].
// is_numeric() function can be used to find whether a variable is numeric. The function returns true if the variable is a number or a numeric string, false otherwise.
// // Cast float to int, $x = 23465.768;, $int_cast = (int)$x; -> 23465.
// To create a constant, use the define() function. -> define(name, value, case-insensitive[ Default is false]), Constants are Global.

// Array -> $cars = array("Volvo", "BMW", "Toyota"); count($cars), sort($cars), rsort($cars)[reverse sort];

// associative array -> $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); According to Value - asort(), According to Key - ksort(),  According to Value - arsort(),  According to Key - krsort().
?>

$items = array('yash', 'vat', 'hello', 'ninja', 'zinc');
foreach ($items as $k) {
    echo $k;
    echo '<br>';
}

Dates:
// $d = date('l'); -> day of the week
// $d = date("Y/m/d"); -> year/month/date
// $d = date('Y-m-d'); -> different format
date_default_timezone_set("America/New_York");
echo date_default_timezone_get();
H - 24-hour format of an hour (00 to 23)
h - 12-hour format of an hour with leading zeros (01 to 12)
i - Minutes with leading zeros (00 to 59)
s - Seconds with leading zeros (00 to 59)
a - Lowercase Ante meridiem and Post meridiem (am or pm)

Comments