PHP class notes


There have been too many things (bullshit) recently
Study time was squeezed
What do you have to do when you have to dance
And made it to the finals
Win honor (disgrace) to the whole school

I've been playing games lately
I did learn something
All the masters tttql
At the same time, I increasingly feel that the foundation is very important
I didn't study PHP so carefully before
So now turn around and take notes again

stay hungry stay foolish

PHP variable

Weakly typed language
Output variable type function:
var_dump (variable name) can output the type of variable
1. bool (Boolean)
Booleans express true or false, that is, true or false.
The following values are considered false
(1) Boolean false
(3) Floating point 0.0
(4) Blank string and string 0
(5) Array without members
2. int (integer)
Store integer
$a = 1;

echo $a;

3. float (floating point)
Store decimal
$b = 6.6;

echo $a;

4. String (string)
A string is a series of characters
Strings can be defined in three ways: single quotation marks, double quotation marks and delimiters
be careful:

	(1)Content enclosed in single quotation marks cannot be enclosed in single quotation marks again
 Solution: you can use\Escape
$a = 'ki10'Mac'(×)
$a = 'ki10'Mac';

$a = 'ki10\'Mac'(√)
$a = 'ki10\'Mac';

  (2)Variables that appear in a single quoted string are not replaced by the value of the variable, that is PHP Variables in single quotes are not resolved
  (3)The variable appearing in the double quoted string will be replaced by the value of the variable, but if you want to PHP Parsing requires{}(Curly braces) include variables.
  (4)Delimiter (single and double quotation marks can be added at will)
   $k = 78;
	$b = 4399games{$b}7k7kgames
	stay $a=<<<and aaa;Between them is the code area. For the processing method of string, refer to the use of double quotation marks.

5. array
6. object
7. resource
null means that a variable has no value and is empty.
Directly assign the variable to null.
The declared variable has not been assigned.
The variable destroyed by the unset function.


PHP constant

1, Concept: a constant is an identifier (name) of a simple value.
Constants are containers for storing values (data) temporarily (only when the program is running)
2, Definition and use
The naming of constants is similar to that of variables and follows the naming rules of PHP identifiers. By convention, constant identifiers are always capitalized
define('constant name ', constant value)
define("constant name", constant value)

define('waste material','ki10Moc');
echo waste material;

The defined() function to check whether a constant is defined
3, The difference between constants and variables
1. Constant not preceded$
2. Constants can only be defined with the define() function, not through assignment statements
3. Constants can be defined and used anywhere, not limited to the rules of variable scope
4. Once a constant is defined, it cannot be redefined or undefined
5. Constant values can only be bool, int, float, string types
4, Predefined constants
Predefined constants can be directly used in the program to complete some special functions

(1)echo FILE ; // Gets the absolute address of the current file

echo __FILE__ ;

(2)echo dirname(FILE); // Gets the absolute directory where the current file is located

echo dirname(__FILE__);

(3)echo dirname(dirname(FILE)); // Gets the directory name above the current file

echo dirname(dirname(__FILE__));

PHP variable type conversion

1, Automatic type conversion
(1) When Boolean values are involved in the operation, true will be converted to integer 1 and false will be converted to integer 0
(2) When there is a null value involved in the operation, the null value is converted to integer 0 for operation
(3) When there are int type and float data involved in the operation, first convert int to float type before operation
(4) There are string and numeric types involved in the operation
2, Cast type
Enclose the target type in parentheses before the variable to be converted



The transformation does not change the type of the variable itself
3, Test function of variable type

#The following code I use VaR_ Whether the output of dump is Boolean, because if print is used_ If R is true for Boolean value, 1 will be output; otherwise, it will not be output
//is_null - detects whether the variable is NULL
$a = null;
//is_int -- detects whether the variable is an integer
//is_ The integer function is is_ Alias function of int().
$num = 9;
$num = '9';
//is_numeric tests whether a variable is a number or a numeric string, such as form input. They are usually strings 
$num = 9;
$num = '9';
//is_double — is_ The alias of float() detects whether the variable is floating-point
//is_real — is_ Alias for float()
$num = 9.99;
//is_string -- check whether the variable is a string
$str = 'Tacks';
//Detect whether the variable is an array	
$arr = array('T','a','c','k','s');
//is_bool -- check whether the variable is Boolean
$bool = true;
//is_object - detects whether the variable is an object
class Obj{}
$obj = new Obj();
//is_resource -- detect whether the variable is of resource type
$fp = fopen('1.php', 'rw');  

Above source: Point me
Subsequent updates

Keywords: PHP Visual Studio Code

Added by Mgccl on Tue, 08 Feb 2022 22:33:50 +0200