博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php变量的几种写法
阅读量:7251 次
发布时间:2019-06-29

本文共 1291 字,大约阅读时间需要 4 分钟。

一、最简单的

 

[php] 
 
 
 
  1. $str = 'Hello World!';  

二、来个变种

 

 

[php] 
 
 
 
  1. $str = 'good';  
  2. $good = 'test';  
  3. $test = 'Hello World!';  
  4. echo $$$str; // Hello World!  

应该都能明白吧。

 

三、放在引号内的

 

[html] 
 
 
 
  1. $str = 'Hello World!';  
  2.   
  3. echo '$str';// $str  
  4. echo "$str";// Hello World!  

四、list方法来接收

 

 

[html] 
 
 
 
  1. list($a, $b, $c, $d) = array(1, 2, 3, 4);  
  2. echo $a, $b, $c, $d; // 1234  

 

五、界定符

 

[html] 
 
 
 
  1. $num = '11';  
  2.   
  3. $str = <<<EOT  
  4. CREATE TABLE IF NOT EXISTS `tp_info` (  
  5.   `id` int({$num}) NOT NULL AUTO_INCREMENT,  
  6.   `name` varchar(60) NOT NULL,  
  7.   PRIMARY KEY (`id`)  
  8. ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1  
  9. EOT;  

 

六、高大上的

 

[html] 
 
 
 
  1. $toUserName = 'fans';  
  2. $fromUserName = 'molaifeng';  
  3. $createTime = time();  
  4. $msgType = 'text';  
  5. $content = '高大上';  
  6.   
  7. $textTpl = "<xml>  
  8.             <ToUserName><![CDATA[%s]]></ToUserName>  
  9.             <FromUserName><![CDATA[%s]]></FromUserName>  
  10.             <CreateTime>%s</CreateTime>  
  11.             <MsgType><![CDATA[%s]]></MsgType>  
  12.             <Content><![CDATA[%s]]></Content>  
  13.             <FuncFlag>0</FuncFlag>  
  14.             </xml>";  
  15. echo sprintf($textTpl, $toUserName, $fromUserName, $createTime, $msgType, $content);  

 

【update】

最近刚好把C的语法学完,正好有个知识点是对PHP有用的。因为PHP是用C编写的,在ANSI C中,对标记解析使用“maximal munch strategy(最大一口策略)”,这种策略表示如果下一个标记有超过一种的解释方案,编译器将选取能组成最长字符序列的方案。

 

[cpp] 
 
 
 
    1. $a = 2;  
    2. $aa = 22;  
    3. $aaa = 222;  
    4.   
    5. echo "$aaa"; // 222  
如何联系我:【万里虎】www.bravetiger.cn 【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起) 【博客】http://www.cnblogs.com/kenshinobiy/
你可能感兴趣的文章
什么时候开始不算晚?
查看>>
页面无阻塞加载研究
查看>>
java.util.concurrent包(1)——synchronized和lock
查看>>
Android Root Source Code: Looking at the C-Skills
查看>>
shell 脚本简介
查看>>
【Transact-SQL】一句SQL删除重复记录
查看>>
bash编程之算术运算
查看>>
服务器类型
查看>>
安装VIM8和vim-go插件
查看>>
安装SCCM2012 R2
查看>>
CentOS6.5 NFS服务器的安装与基本参数
查看>>
I/O多路转接之select
查看>>
让有些“-l”链接静态库,而另一些链接共享库?
查看>>
使用Webstorm操作git
查看>>
uboot移植之start_armboot()函数分析
查看>>
移动办公是不能阻挡的未来办公趋势
查看>>
docker简单介绍及安装
查看>>
DNS服务(1)基本概念详解
查看>>
Redhat7DNS搭建
查看>>
python之rabbitMQ
查看>>