如何将数组中的不同数组合并到php中的一个单维数组中?

时间:2016-11-17 06:36:53

标签: php arrays

我在foreach循环中创建一个数组。该数组包含我从谷歌游戏商店获取的值。我想要做的是将不同的数组组合成一个单维数组。外部数组没有键。如何在没有键的情况下组合所有子数组。我展示的结果是相同的数组而不是不同的数组,所以这个问题是不同的。请帮我。提前致谢。

用于获取值的php函数

function gplaystore_get_single_product_card_link($link){
    $final_array=array();
    $html = file_get_contents($link);   
    $gplay_doc = new DOMDocument();
    libxml_use_internal_errors(TRUE);
    if(!empty($html)){
        $gplay_doc->loadHTML($html);
        libxml_clear_errors();
        $gplay_xpath = new DOMXPath($gplay_doc);
        $gplay_row = $gplay_xpath->query('//a[@class="card-click-target"]/@href');

        if($gplay_row->length > 0){
            foreach($gplay_row as $key=>$val){
                $final_array[] = 'https://play.google.com'.$val->nodeValue;
            }
        }       
    }


    echo '<pre>';
    print_r($final_array);
    echo '</pre>';
}

我得到的结果

Array
(
    [0] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
    [1] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
    [2] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
    [3] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
    [4] => https://play.google.com/store/apps/details?id=codeadore.textgram
}
Array
(
    [0] => https://play.google.com/store/apps/details?id=com.autoscout24
    [1] => https://play.google.com/store/apps/details?id=com.autoscout24
    [2] => https://play.google.com/store/apps/details?id=com.autoscout24
    [3] => https://play.google.com/store/apps/details?id=com.autoscout24
    [4] => https://play.google.com/store/apps/details?id=ru.gibdd_pay.app
    [5] => https://play.google.com/store/apps/details?id=ru.gibdd_pay.app
}
Array
(
    [0] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
    [1] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
    [2] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
    [3] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
    [4] => https://play.google.com/store/apps/details?id=in.letstartup.GoraTips
    [5] => https://play.google.com/store/apps/details?id=in.letstartup.GoraTips
}

我想要的实际结果

 Array
    (
        [0] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
        [1] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
        [2] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
        [3] => https://play.google.com/store/apps/details?id=com.depthapps.stylish.name.maker
        [4] => https://play.google.com/store/apps/details?id=codeadore.textgram
        [5] => https://play.google.com/store/apps/details?id=com.autoscout24
        [6] => https://play.google.com/store/apps/details?id=com.autoscout24
        [7] => https://play.google.com/store/apps/details?id=com.autoscout24
        [8] => https://play.google.com/store/apps/details?id=com.autoscout24
        [9] => https://play.google.com/store/apps/details?id=ru.gibdd_pay.app
        [10] => https://play.google.com/store/apps/details?id=ru.gibdd_pay.app
        [11] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
        [12] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
        [13] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
        [14] => https://play.google.com/store/apps/details?id=com.northpark.beautycamera
        [15] => https://play.google.com/store/apps/details?id=in.letstartup.GoraTips
        [16] => https://play.google.com/store/apps/details?id=in.letstartup.GoraTips
    }

0 个答案:

没有答案