【问题标题】:How can i put $variable into array如何将 $variable 放入数组
【发布时间】:2015-06-07 19:01:15
【问题描述】:

您好,这是我想将变量放入数组的代码

    class NewTest extends BaseExample {
  public function render() {
    $startDate = $this->getNow();
    $endDate = $this->getNow();
    $optParams = array(
      'metric' => array('EARNINGS'),
      'useTimezoneReporting' => true,
      'filter' => 'DOMAIN_NAME==' .$sub. ',      
    );

我尝试过' .$sub.' 和 $sub 但它不起作用

【问题讨论】:

  • 您在过滤器行的末尾缺少'

标签: php arrays variables echo


【解决方案1】:

轻微的语法错误 - 只需删除最后的 . '

class NewTest extends BaseExample {
  public function render() {
   $startDate = $this->getNow();
   $endDate = $this->getNow();
   $optParams = array(
    'metric' => array('EARNINGS'),
    'useTimezoneReporting' => true,
    'filter' => 'DOMAIN_NAME==' . $sub,      
   );
 }
}

【讨论】:

【解决方案2】:

缺少'

'filter' => 'DOMAIN_NAME==' .$sub. '', 

既然没用,应该更好

'filter' => 'DOMAIN_NAME==' .$sub, 

【讨论】:

【解决方案3】:

去掉'

    class NewTest extends BaseExample {
  public function render() {
    $startDate = $this->getNow();
    $endDate = $this->getNow();
    $optParams = array(
      'metric' => array('EARNINGS'),
      'useTimezoneReporting' => true,
      'filter' => 'DOMAIN_NAME==' .$sub,      
    );

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 2022-01-11
    • 2020-03-17
    • 1970-01-01
    相关资源
    最近更新 更多