php - 如何从这样的数组 $A= Array ( [Count(funded_by)] => 10) 中获取值 (10)?

标签 php mysql

代码:

$A = Array ( [Count(funded_by)] => 10);
echo $A['Count(funded_by)'];

错误:

E_NOTICE : type 8 -- Use of undefined constant funded_by - assumed 'funded_by' -- at line 3

E_WARNING : type 2 -- Illegal offset type -- at line 3

E_NOTICE : type 8 -- Undefined index: Count(funded_by) -- at line 4

最佳答案

你不能这样定义一个变量。您需要单引号而不是方括号。

<?php        

$a = array( 'Count(funded_by)' => 10);
echo $a['Count(funded_by)'];

因为您在另一条评论中提到这是查询的结果。通常您会在查询中执行此操作以使其更易于访问:

SELECT COUNT(funded_by) AS total FROM your_table;

然后当您获取结果时,您可以使用 $result['total'] 访问它。 total 成为 COUNT(funded_by)

值的别名

关于php - 如何从这样的数组 $A= Array ( [Count(funded_by)] => 10) 中获取值 (10)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34670828/

相关文章:

php - 从快捷方式 IF 语句在 Blade 模板中渲染 HTML

php - 升级 Extjs 3.3 到最新版本

mysql - MySQL有没有一个函数可以将多个单元格中的数据提取到一个单元格中

mysql - 我怎样才能过滤我的表,以便它显示最新的数据?

python - 在 python 元组中格式化来自 mysql 的数据

php - Laravel 5.4 中任何用户登录时喜欢和不喜欢的功能

php - 使用 PHP - PayPal 设置即时付款通知

php - 实时 ffmpeg shell 输出 PHP

php - 匹配的 Codeigniter 表单验证规则(密码)

java - 使用java连接mysql