PHP common features, php_php tutorials

Source: Internet
Author: User

PHP Common features, PHP


1.PHP string
    • The string declares the variable = ' ' or ' (the general case uses single quotes because it is easier to write)
$str = ' Hello PHP '; Echo $str;
    • Strpos to calculate the position of a character in a string (starting at 0)
$str = ' Hello PHP '; Echo Strpos ($str, ' o ');  // calculates the position of a character in a string Echo '
'; Echo Strpos ($str, ' PH ');
    • SUBSTR Intercept string
$str = ' Hello PHP '; // Intercept String $str 1 substr ($str// intercept from 2 position, intercept string with length 3 echo$str 1;
If the length parameter is not passed, it will be truncated from the specified position to the end of the string.
    • Str_split split string fixed-length split (default length is 1)
$str = ' Hello PHP '; // Split String $result Str_split ($str);   // Save the result in an array Print_r ($result);  // enter an array using Print_r Echo '
'; $result 1 Str_split ($str, 2); Print_r ($result 1);
    • Explode (split character, string to be split) separated by space
$str = ' Hello PHP Java C # C # '; $result Explode (',$str); Print_r ($result);
    • Connection of strings
$str = ' Hello PHP Java C # C # '; // Connection of Strings $num = +; $str 1 $str. '
Objective-c '. $num ; Echo $str 1 ; Echo '
'; $str 2 = "$str
$num"; // another easy way to do it Echo $str 2;

2.PHP arrays
    • Array declaration PHP arrays are very dynamic and can store all types of data
// how arrays are declared $arr Array (); $arr [0] = ' Hello '; $arr [1] = ' world '; $arr [2] = 2; $arr [3] = 3.14; Print_r ($arr);
    • Array_push ()//Add an element
    • Array_pop ()//delete last element
$arr Array ();  for ($i= 0; $i<100; $i+ +)    {array_push($arr, ' Item ').  $i);} Print_r ($arr);
    • Storing data by key-value pairs (key-value)
$arr Array (); $arr [' H '] = ' Hello '; $arr [' W '] = ' world '; Print_r ($arr); Echo '
'; Echo $arr [' H '];
Output: Array ([H] = = Hello [W] = world) Hello
    • Not only can the PHP array be used as an array, but also can be used as a map
    • Array initialization
$arr Array (' H ' = ' Hello ', ' W ' = ' world ');    // Initialization of PHP arrays Print_r ($arr);
    • You can have array markers at the same time, and key-value pairs
$arr Array (0=> ' make ',1=> ' Tom ', ' H ' = ' Hello ', ' W ' = ' ' World '); Print_r ($arr); Echo '
'; Echo $arr [0]; Echo '
'; Echo $arr [' W '];
Output: Array ([0] = make [1] = Tom [H] = = Hello [W] = World

http://www.bkjia.com/PHPjc/1069668.html www.bkjia.com true http://www.bkjia.com/PHPjc/1069668.html techarticle php common Functions, PHP 1.PHP string string declaration variable = "" or "" (generally use single quotation marks, because it is easier to write) $str = ' Hello php '; echo $str; Strpos meter ...

  • 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.