Video-03No.2PHP basic syntax ?? & Lt ;! -- Moditybyshma1664 -- & gt; & lt ;? Php ** php id number definition rules: before the definition of the same variable * as Java, a $ symbol should be added to mark * PHP as a weak language, this is familiar with JavaScript * PHP supports the following basic data types: Integer, Floa Video-03 No. 2 PHP Basic syntax
?
?
");/** Data type conversion: Forced conversion * gettype (): Gets the type of a variable. the returned value is a type string */$ sum = 25.6; echo gettype ($ sum); $ count = (int) $ sum; echo gettype ($ count); echo ("
"); Echo ("
");/** Settype (): sets the variable type. the returned value is a boolean value. whether the value is set successfully */echo ("
"); $ Num1 = 100; echo settype ($ sum1," string "); // boolean, integer, float, array, object, nullecho ("
"); Echo $ num1; echo ("
"); Echo (" -------------------------------- "); echo ("
");/** Isset (variable name, variable name ..): determines whether a variable exists * unset (variable name, variable name ...): destroy a variable */$ num2 = 12.58; $ num3 = 12; echo isset ($ num2, $ num3); echo isset ($ num3); unset ($ num2, $ num3); echo isset ($ num2); echo isset ($ num1); echo isset ($ num1, $ num3); echo ("
"); Echo (" -------------------------------- "); echo ("
");/*** Empty (variable name): determines whether a variable is null * if it is null, 1 is returned. if it is not null, 0 * null, 0 ,"", "0", false, array (), var $ var, and no attribute objects will be treated as null */$ num4 = 12.4; $ num5 = ""; $ num6 = (boolean) 0; $ num7 = null; echo (empty ($ num4); echo (empty ($ num5); echo (empty ($ num6 )); echo (empty ($ num7); echo ("
"); Echo (" -------------------------------- "); echo ("
");/*** Determines whether the variable belongs to a certain type. * If yes, true is returned. otherwise, false */echo is_double ($ num4) is returned ); echo is_float ($ num4); echo is_int ($ num4); echo is_long ($ num4); echo is_null ($ num4); echo is_object ($ num4 ); echo is_array ($ num4); echo is_string ($ num4); echo ("
"); Echo (" -------------------------------- "); echo ("
");/** Temporary conversion variable * intvar (), floatvar (), strvar (): The temporary conversion variable type is int, float, string */$ num8 = 10.1; echo gettype ($ num8); echo intval ($ num8); echo gettype (intval ($ num8); echo floatval (intval ($ num8 )); echo gettype (floatval (intval ($ num8); echo strval ($ num8); echo gettype (strval ($ num8); echo gettype ($ num8); echo ("
"); Echo (" -------------------------------- "); echo ("
"); // Defines a constant. after a constant is defined, its value cannot be changed in define (" TOTAL ", 23); echo TOTAL; // default PHP constant, defined in phpinfo () echo phpinfo (); echo ("
"); Echo $ _ SERVER [" SERVER_NAME "].": ". $ _ SERVER [" SERVER_PORT "];?>
?
? Form processing:
?
"; Echo" the password you entered is: ". $ pwd;?>
?
: Valid in front-end of browser webpage, invalid in back-end source code * escape character: invalid in front-end browser. Valid * escape character: * \ n: linefeed * \ r: Carriage return * \ t: horizontal tab * \: Backslash * \ $: dollar character * \ ": Double cited CHARACTER */$ username =" shma "; $ username2 =" Ma Shaohua "; echo" His name is $ username "; echo'
'; Echo 'His name is $ username'; echo"
"; Echo" his name is $ username2. he is 23 years old! "; // Echo cannot be displayed"
"; Echo" his name is ". $ username2.", he is 23 years old! "; Echo"
"; Echo" his name is ". $ username2.", \ n he is 23 years old! "; Echo"
"; Echo 'His name is". $ username2. ", \ n he is 23 years old! ';/** = And = *! = And! = * Constant equals indicates that only two operands are equal and the types are the same, or not */$ a = 6; $ B = 5; $ c = "5"; echo'
'; Echo $ a ==$ B; echo $! = $ B; echo $ a ===$ B; echo $! ==$ B; echo $ c ===$ B; echo $ c ==$ B; // error suppression operator @ $ num =@ (10/0 ); echo "$ num"; $ value = 10; echo "value = ". ($ value> 1? $ Value: "0"); // mathematical operation/** +: calculation between numbers *.: string operation */$ a1 = 'a'; $ b1 = 5. $ a1; echo $ b1; // is_numeric-check whether the variable is a numeric or numeric string $ a = 123; if (is_numeric ($ a) {echo $. "is a number";} else {echo $. "Not a number";} echo"
"; // Obtain the random number echo rand (); echo"
"; Echo rand (1, 10); echo"
"; Echo mt_rand (); echo"
"; Echo maid (1, 10000); echo"
"; Echo getrandmax (); echo"
"; Echo mt_getrandmax (); // format the data $ a = 10324.564343; echo"
"; Echo"
"; Echo number_format ($ a); echo number_format ($ a, 2); echo number_format ($ a, 2 ,"#","! "); // Mathematical operation $ B =-6.3; echo abs ($ B); echo min (, 6,-5); echo max, 6,-5);?>
?
?