数据库读出来的数据如何与定义好的常量对应
程序员文章站
2024-01-06 14:59:40
...
数据库读出来的数据怎么与定义好的常量对应?
consstant.php:
define("town_9","横沥");
define("town_10","桥头");
define("town_11","谢岗");
define("town_12","东坑");
define("town_13","常平");
define("town_14","寮步");
define("town_15","大朗");
define("town_16","黄江");
test.php:
...//数据库操作
echo $row[0];//$row[0]输出是town_14
?>
这样运行test.php显示出来是town_14,而输出定义好的常量寮步.这如何是好?
------解决方案--------------------
consstant.php:
define("town_9","横沥");
define("town_10","桥头");
define("town_11","谢岗");
define("town_12","东坑");
define("town_13","常平");
define("town_14","寮步");
define("town_15","大朗");
define("town_16","黄江");
test.php:
...//数据库操作
echo $row[0];//$row[0]输出是town_14
?>
这样运行test.php显示出来是town_14,而输出定义好的常量寮步.这如何是好?
------解决方案--------------------
define("town_9","横沥");
define("town_10","桥头");
define("town_11","谢岗");
define("town_12","东坑");
define("town_13","常平");
define("town_14","寮步");
define("town_15","大朗");
define("town_16","黄江");
//数据库操作
$row = array();
$row[0] = "town_14";
$defined_constants = get_defined_constants();
echo $defined_constants[$row[0]]; // 寮步
相关文章
相关视频
上一篇: php 图片转换成ascii 输出图像