PHP _php Examples of some interview topics on variable and date handling

Source: Internet
Author: User
Variable correlation
Internal implementation of PHP variables
The system type of a programming language is divided into two types: strong and weak.

    1. A strongly typed language is one in which a variable is declared as a variable of a certain type, and it cannot be assigned to a value other than the type of the variable in the course of the program's operation, such as C/c++/java.
    2. Scripting languages such as PHP and Ruby,javascript are weak-type languages: A variable can represent any data type


PHP variable type and storage structure
PHP does not need to explicitly indicate its data type when declaring or using a variable

PHP is a weakly typed language, which does not mean that PHP has no type, in PHP, there are 8 types of variables, can be divided into three categories:

    1. Scalar type: boolean,integer,float,string
    2. Compound Type: array,object
    3. 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     zend_uint refcount__gc;//= reference count     zend_uchar type;  Variable-specific type     Zend_uchar is_ref_gc;  Indicates whether it is a reference   


The value of the variable is stored in another struct zvalue_value

Variable type
The Type field of the Zval struct is the most critical field for implementing the 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 well understood, they're just types of unique markers that store different values in the Value field depending on the type

Storage of variable values
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;   


Date related

Calculate the number of days between two dates

<?php      /**    * For days between two dates (Taylor formula can be used after January 1, 1970)    * @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);   
  • 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.