Variable related
Internal implementation of PHP variables
the system type of the programming language is divided into strong type and weak type two kinds:
- A strongly typed language is one in which a variable is declared as a variable of a type, and a value other than the type of the variable cannot be assigned to it while the program is running, and C/c++/java languages fall into this category
- Scripting languages such as PHP and Ruby,javascript are weakly typed languages: A variable can represent any type of data
PHP variable type and storage structure
when you declare or use a variable, PHP does not need to explicitly indicate its data type
PHP is a weak type language, which does not mean that PHP has no type, in PHP, there are 8 types of variables, can be divided into three categories:
- Scalar type: boolean,integer,float,string
- Composite type: Array,object
- Special type: Resource,null
Variable Storage structure
the value of the variable is stored in the ZVAL structure shown below. Its structure is as follows:
typedef struct _ZVAL_STRUCT zval;
struct _zval_struct {
zvalue_value value;//storage variable values
zend_uint refcount__gc;//representing reference count
Zend_uchar type; Variable-specific type
Zend_uchar is_ref_gc; Indicates whether it is a reference
};
The value of a variable is stored in another struct zvalue_value
Variable type
the Type field of the ZVAL structure is the most critical field for implementing a weak type, and the value of type can be: Is_null, Is_bool, Is_long, is_double, is_string, Is_array, Is_object, Is_ One of the resource. Literally understood that they were just types of unique labels, depending on the type of different values stored in the Value field
Storage of variable values
as mentioned earlier, the value of the variable is stored in the zvalue_value structure, and the structure is defined as follows:
typedef Union _ZVALUE_VALUE {
long lval;
Double dval;
struct {
char *val;
int len;
} STR;
HashTable *ht;
Zend_object_value obj;
} _zvalue_value;
Date Related
Calculate the number of days between two dates
<?php
/**
* Find the number of days between two dates (for January 1, 1970, before you can use Taylor Formula)
* @param string $day 1
* @param string $day 2
* @return number
/function Diffbetweentwodays ($day 1, $day 2)
{
$second 1 = strtotime ($day 1);
$second 2 = strtotime ($day 2);
if ($second 1 < $second 2) {
$tmp = $second 2;
$second 2 = $second 1;
$second 1 = $tmp;
}
Return ($second 1-$second 2)/86400;
}
$day 1 = "2013-07-27";
$day 2 = "2013-08-04";
$diff = Diffbetweentwodays ($day 1, $day 2);
echo $diff. " \ n ";