Php 如何对谷歌生成的关键词创意结果进行排序?
尽管如此,我还是成功地实现了Google Keyword Planner API,通过下面的链接在PHP中生成关键字创意 有人知道用avgmonthlysearch对结果进行排序的最快方法吗Php 如何对谷歌生成的关键词创意结果进行排序?,php,google-ads-api,Php,Google Ads Api,尽管如此,我还是成功地实现了Google Keyword Planner API,通过下面的链接在PHP中生成关键字创意 有人知道用avgmonthlysearch对结果进行排序的最快方法吗 // Iterate over the results and print its detail. foreach ($response->iterateAllElements() as $result) { /** @var GenerateKeywordIdeaResult $resul
// Iterate over the results and print its detail.
foreach ($response->iterateAllElements() as $result) {
/** @var GenerateKeywordIdeaResult $result */
// Note that the competition printed below is enum value.
// For example, a value of 2 will be returned when the competition is 'LOW'.
// A mapping of enum names to values can be found at KeywordPlanCompetitionLevel.php.
printf(
"Keyword idea text '%s' has %d average monthly searches and competition as %d.%s",
$result->getText(),
is_null($result->getKeywordIdeaMetrics()) ?
0 : $result->getKeywordIdeaMetrics()->getAvgMonthlySearches(),
is_null($result->getKeywordIdeaMetrics()) ?
0 : $result->getKeywordIdeaMetrics()->getCompetition(),
PHP_EOL
);
}
谢谢您可以实现一个功能,可以比较对象的两个实例并使用:
函数cmp($a,$b){
返回$a->getKeywordIdeaMetrics()->getAvgMonthlySearches()-$b->getKeywordIdeaMetrics()->getAvgMonthlySearches();
}
$list=iterator_to_数组($response->->->iterateAllements());
usort($list,“cmp”);
//$list将是从此处开始使用的排序数组。。。
请参阅更多:
iterator\u to\u array
转换为数组才能使用usort
。如果您想尝试,我更新了答案的代码。请注意,这不会给您带来最佳性能。要获得最佳性能,您应该直接在查询中对结果排序。请参阅排序依据
条款