代码:
$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/