当从另一个php文件调用函数时,返回数组的最后一项

当从另一个php文件调用函数时,返回数组的最后一项,php,arrays,google-analytics-api,Php,Arrays,Google Analytics Api,我是PHP的新手。我希望从一个php文件中的函数返回一个数组,并访问另一个php文件中的数组元素 我面临的问题是,当我运行源文件并打印数组元素时,我能够在控制台中看到所有标记,但当我返回数组并在另一个php文件中打印它时,只返回一个项或不返回任何项 source file.php <?php // Load the Google API PHP Client Library. require_once 'C:/xxxx/google-api-php-client-2.2.4/vendor

我是PHP的新手。我希望从一个php文件中的函数返回一个数组,并访问另一个php文件中的数组元素

我面临的问题是,当我运行源文件并打印数组元素时,我能够在控制台中看到所有标记,但当我返回数组并在另一个php文件中打印它时,只返回一个项或不返回任何项

source file.php

<?php

// Load the Google API PHP Client Library.
require_once 'C:/xxxx/google-api-php-client-2.2.4/vendor/autoload.php';


function getTags(){

    $KEY_FILE_LOCATION = 'C:/xxx/service-account-credentials.json';

    $params=array(
        'dimensions' => 'ga:dimension5,ga:dimension2',
        'filters' => 'ga:dimension5==123456'
    );
    $results =  $analytics->data_ga->get(
        'ga:' . 123456,
        '2019-08-29',
        'yesterday',
        'ga:sessions',
        $params
        );

        $rows = $results->getRows();
        $StoreTags = array();

        for($i=0;$i<sizeof($rows);$i++){

            $ExtractTag_arr = explode(',',$rows[$i][1]);

            for($j=0;$j<count($ExtractTag_arr);$j++){
                $StoreTags[]=$ExtractTag_arr[$j];
            }

            $ExtractTag_arr='';
        }

        $unique_tags = array_unique($StoreTags);
        $Unique_tags_Values = array_values(array_filter($unique_tags));
        $Count_UniqueTags = count($Unique_tags_Values);
        $Count_StoreTags=count($StoreTags);

        for($a=0;$a<$Count_UniqueTags;$a++){

            $Count_Occurances = 0;
            $UniqueTags_Value = $Unique_tags_Values[$a];

            for ($k=0;$k<$Count_StoreTags;$k++){

                if ($UniqueTags_Value == $StoreTags[$k]){

                    $Count_Occurances = $Count_Occurances+1;
                }
                else{
                    $Count_Occurances = $Count_Occurances+0;

                }
            }

           $Display_Tags=array($Unique_tags_Values[$a], $Count_Occurances);

            return  $Display_Tags;
        }

}
1.
get_tags=getTags()
不正确,需要是
$get_tags=getTags()

2.
Print_r(getTags())需要
打印(getTags())

3.为了解决您的问题,请放置
返回$Display\u标签在函数
getTags()
中的
for()
循环之外

1.
get_tags=getTags()
不正确,需要是
$get_tags=getTags()

2.
Print_r(getTags())需要
打印(getTags())

3.为了解决您的问题,请放置
返回$Display\u标签在函数
getTags()
中的
for()
循环之外


for
loop?1的第一个
中似乎有返回语句
不正确,需要是
$get_tags=getTags()0.2.
打印(getTags())需要
打印(getTags())
for
loop?1的第一个
中似乎有返回语句。
get_tags=getTags()
不正确,需要是
$get_tags=getTags()0.2.
打印(getTags())需要
打印(getTags())感谢您的回复,将测试并接受回答抱歉更新错误,但当从另一个php文件调用时,我只收到1项任何关于如何解决的想法,请遵循您的所有建议steps@Siva若答案不适用于你们,那个么你们为什么要标记它?它声明您的问题已解决。是的,很抱歉,我正在查看代码中的其他点,并且看起来您的答案有效,因此将其标记为Answered感谢回复,将测试并接受它作为Answered抱歉更新错误,但当从另一个php文件调用时,我只收到1项任何有关如何解决的想法,跟着你的steps@Siva若答案不适用于你们,那个么你们为什么要标记它?它表明您的问题已解决。是的,很抱歉,我正在查看代码中的其他点,看起来您的答案有效,因此将其标记为已回答
<?php
include 'Source.php';

get_tags = getTags();
Print_r(getTags());
<?php
include 'Source.php';

$get_tags = getTags();
print_r($get_tags);