一、不管什么程序,function name(){}, for(){}, ….太多了,不说也知道做什么用了。 二、$str{4}在字符串的变量的后面跟上{}刚大括号和中括号一样都是把某个字符串变量当成数组处理。 三、{$val}这时候大括号起的作用就是,告诉PHP,括起来的要当成变量处理。 代码如下: $arr=array(0=>123, 'name'=>'你好'); foreach($array as $k=>$v){ echo "select * from blog_blogs where blog_tags like '%{$arr[$k]}%' order by blog_id"; //加一个大括号只是将作为变量的标志符 } echo '
'; foreach($array as $k=>$v){ echo "select * from blog_blogs where blog_tags like '%{{$arr[$k]}}%' order by blog_id"; //加两个大括号,外层的将作为普通的字符 } //用大括号来区分变量 //echo "$arr['name']"; //用此句会报语法错误 echo "{$arr['name']}"; //此句正常,大括号内的字符将作为变量来处理 //$str{4} 在字符串的变量的后面跟上{} 大括号和中括号一样都是把某个字符串变量当成数组处理 $str = 'abcdefg'; echo $str{4};
引用 In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] as a variable, or if you wanted $$a as the variable and then the [1] index from that variable. The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second. 也就是说,为了在数组环境中也可以使用可变变量,因此,需要根据不同的情况,恰当的使用大括号{}限制变量的范围。${$a[1]} 与${$a}[1] 是完全不同的:
引用 123123123 Notice: Use of undefined constant test - assumed 'test' in /var/www/html/phpcrm/testpages/variables.php on line 6 123_ Notice: Use of undefined constant test - assumed 'test' in /var/www/html/phpcrm/testpages/variables.php on line 7 123 这说明什么? 1、可接受的写法 从输出结果中“123123123”,表明前面三行的echo语句都是正常的: 代码如下: echo $test; echo "${test}"; echo "{$test}";
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