php 中 define 定义常量和单双引号问题
来源:互联网 发布:怎样与淘宝买家联系 编辑:程序博客网 时间:2024/05/18 10:16
一、define定义常量问题
<?php
define('DATABASE', 'MYSQL');
define('DATABASE_USER', 'ROOT');
define('DATABASE_PASSWORD', 'PASSWORD');
?>
直接使用"DATABASE"常量,代表的就是"MYSQL"。
$arr = array('fruit'=>'apple','veggie'=>'carrot');
define('fruit','veggie');
print $arr['fruit']; // apple
print $arr[fruit]; // carrot
* 注意 :[] 中没有引号。php会自动把key值当作常量来解析,然后去内存中找对应的常量,于是找到了fruit,然后解析key值。然后再去内存中找常量,没找到veggie,然后就把veggie当作真正的key值,找到对应的值。
二、单双引号问题
error_reporting(E_ALL);
$arr = array('fruit'=>'apple','veggie'=>'carrot');
define('fruit','veggie');
print $arr['fruit']; echo '<br/>'; //apple
print $arr[fruit]; echo '<br/>'; //carrot
print "hello $arr[fruit]"; echo '<br/>'; // apple
print "hello {$arr[fruit]}"; echo '<br/>'; // hello carrot
print "hello {$arr['fruit']}"; echo '<br/>';// hello apple
//print "Hello $arr['fruit']"; // 有错误
//print "hello $_GET['foo']"; // 有错误
print "Hello " . $arr['fruit']; // Hello apple
注意: 数组方括号中如果没有加引号,php会首先按照常量来解析。
- php 中 define 定义常量和单双引号问题
- PHP中const和define()定义常量的细节区别
- PHP中const和define()定义常量的细节区别
- PHP中const和define()定义常量的细节区别
- PHP中const和define()定义常量的细节区别
- PHP中const和define()定义常量的细节区别
- PHP常量定义,define()和const区别
- php const和define的区别(php类中如何定义常量)
- php const和define的区别(php类中如何定义常量)
- php const和define的区别(php类中如何定义常量)
- php中const与define定义常量的区别
- PHP中定义常量的区别,define() vs. const
- PHP定义常量是,const和define的区别
- PHP 定义常量const和define的区别
- 常量定义 const 和define
- php的常量定义:const VS define
- PHP中如何定义和使用常量
- PHP中单引号和双引号的区别之PHP单双引号那些事
- svn 常见图标意义
- MySQL随机查询的优化实例
- MYSQL数据丢失讨论
- Android: ListView与Button的共存问题解决
- HashMap
- php 中 define 定义常量和单双引号问题
- Android杀毒实现原理及实例
- TABLE CONTROL TEST-1
- 判断PC使用的默认浏览器方法
- TreeMap(未完待续)
- 【C++ Primer】标准库vector类型
- java23种设计模式
- xmpp 学习笔记1 - MAC 上openfire 服务器搭建
- 交叉分析制表流程