【问题标题】:How to return result printed in php如何返回用php打印的结果
【发布时间】:2023-04-08 12:37:02
【问题描述】:

我想把打印出来的结果返回给其他函数使用。

代码如下:

"Keyword idea text '%s' has %d average monthly searches and competition as %d.%s",
$result->getText()->getValue(),
is_null($result->getKeywordIdeaMetrics()) ?
0 : $result->getKeywordIdeaMetrics()->getAvgMonthlySearches()->getValue(),
is_null($result->getKeywordIdeaMetrics()) ?
0 : $result->getKeywordIdeaMetrics()->getCompetition(),
PHP_EOL
);

return

结果是这样的:关键字创意文本“a”的平均每月搜索量为 1600 次,竞争为 4。 关键字创意文本“b”平均每月搜索 10 次,竞争次数为 2。 关键字创意文本“c”的平均每月搜索次数为 10,竞争次数为 4。

这是打印出来的

我想像“a,b,c”一样返回

如何将此结果存储在一个字符串中并返回......所以我可以在其他功能中使用

【问题讨论】:

  • return $result->getText()->getValue() . ',' . is_null($result->getKeywordIdeaMetrics()) ? 0 : $result->getKeywordIdeaMetrics()->getAvgMonthlySearches()->getValue() . ',' . is_null($result->getKeywordIdeaMetrics()) ? 0 : $result->getKeywordIdeaMetrics()->getCompetition();
  • 给定代码的确切问题是什么?

标签: php symfony google-ads-api


【解决方案1】:

第一种方法:

return $a . ',' . $b . ',' . $c;

第二种方法

$arr = [$a, $b, $c];
return implode(",", $arr);

【讨论】:

    猜你喜欢
    • 2013-10-23
    • 2015-12-29
    • 1970-01-01
    • 2013-03-31
    • 2017-11-24
    • 2021-10-04
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多