PHP interview questions about variable and date Processing _ php instance

Source: Internet
Author: User
This article mainly introduces some interview questions about variable and date Processing in PHP. It is also the basic knowledge in PHP beginners. For more information, see Variable-related
Internal Implementation of PHP Variables
The system types of programming languages are classified into strong and weak types:

  1. A strongly typed language is a variable that is declared as a certain type. During the program running, values other than the type of the variable cannot be assigned to it, c/c ++/java and other languages belong to this category.
  2. Php, ruby, javascript, and other scripting languages are weak types: a variable can represent any data type.


Php variable type and Storage Structure
Php does not need to explicitly specify its data type when declaring or using variables.

Php is a weak type language, which does not indicate that php has no type. In php, there are eight variable types, which can be divided into three types:

  1. Scalar type: boolean, integer, float, string
  2. Composite Type: array, object
  3. Special Type: resource, NULL


Variable Storage Structure
The value of the variable is stored in the zval struct shown below. Its structure is as follows:

Typedef struct _ zval_struct zval; struct _ zval_struct {zvalue_value value; // The value of the stored variable zend_uint refcount _ gc; // indicates the reference count zend_uchar type; // variable type zend_uchar is_ref_gc; // indicates whether the variable is referenced };


The variable value is stored in the zvalue_value structure.

Variable type
The type field of the zval struct is the most critical field to implement weak types. The type value can be IS_NULL, IS_BOOL, IS_LONG, IS_DOUBLE, IS_STRING, IS_ARRAY, IS_OBJECT, and IS_RESOURCE. literally, they are only unique identifiers of types. Different values are stored in the value Field according to different types.

Storage of variable values
The variable values are stored in the zvalue_value struct. The struct 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

Calculates the number of days between two dates.

<? Php/*** calculate the number of days between two dates (the Taylor formula can be used before the calculation after January 1, January 1, 1970) * @ param string $ day1 * @ param string $ day2 * @ return number */function diffBetweenTwoDays ($ day1, $ day2) {$ second1 = strtotime ($ day1 ); $ second2 = strtotime ($ day2); if ($ second1 <$ second2) {$ tmp = $ second2; $ second2 = $ second1; $ second1 = $ tmp ;} return ($ second1-$ second2)/86400;} $ day1 = "2013-07-27"; $ day2 = "2013-08-04"; $ diff = diffBetweenTwoDays ($ day1, $ day2 ); echo $ diff. "\ n ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.