Home  >  Article  >  Backend Development  >  How much do you know about the function of PHP braces?

How much do you know about the function of PHP braces?

WBOY
WBOYOriginal
2016-07-25 09:00:101627browse
  1. /**
  2. *php braces example solution
  3. *site http://bbs.it-home.org
  4. */
  5. $arr=array(0=>123, 'name'=>'Little Pig');
  6. foreach($array as $k =>$v){
  7. echo "select * from blog_blogs where blog_tags like '%{$arr[$k]}%' order by blog_id"; //Adding a curly bracket just serves as the variable identifier
  8. }
  9. echo '






    ';
  10. foreach($ array as $k=>$v){
  11. echo "select * from blog_blogs where blog_tags like '%{{$arr[$k]}}%' order by blog_id"; //Add two curly brackets, outer layer will be treated as ordinary characters
  12. }
  13. //Use curly brackets to distinguish variables
  14. //echo "$arr['name']";//Using this sentence will report a syntax error
  15. echo "{$arr['name'] }";//This sentence is normal. The characters in the curly brackets will be treated as variables
  16. //$str{4} is followed by {} after the variable of the string. Curly brackets and square brackets are the same as a certain character. String variables are treated as arrays
  17. $str = 'abcdefg';
  18. echo $str{4};
  19. ?>
Copy code


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