Home >Backend Development >PHP Tutorial >Example explanation of PHP string principles_PHP tutorial

Example explanation of PHP string principles_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:30:491144browse

When using , in fact, the PHP string principle is a character array. Suppose we define a string

  1. < ?
  2. $string ="hello world";
  3. /*
  4. This string is composed of h , e , l , l , o , space
    , w ,o,r ,l,d are composed of these characters. As for what ends with
    , I can understand it now. You may need to check the original PHP code to find out
  5. */
  6. //What is the basis for what I said above? The following can be tested
  7. echo $string[2];
    //The third character l is displayed, we can try to change
  8. $string[2]="A";
    //Change one of the characters;
  9. echo $string;
    // Get heAlo world
  10. //Then we can try to change $string[2] to string
  11. $string[2]="AAAAAA";
    / /Test to see if PHP will overwrite the characters behind it
  12. echo $string;
    // Get heAlo world, haha ​​It seems that PHP has done safety processing
  13. ?>

How about, through the above code examples, can you clearly understand the PHP string principle? Everyone can slowly experience it in actual operations in the future.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446264.htmlTechArticleIn fact, when using PHP string principle, it is a character array. Suppose we define a string? $ string = helloworld; /* This string is composed of the characters h, e, l, l, o, space, w, o, r, l, d...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn