Merge multiple arrays without array_merge (), be subject to the Forum.

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_42565994/article/details/102775128

Ideas: through each array, re-form a new array.

<?php
function t(){
    $c = func_num_args()-1;
    $a = func_get_args();
    //print_r($a);
    for($i=0; $i<=$c; $i++){
        if(is_array($a[$i])){
            for($j=0; $j<count($a[$i]); $j++){
                $r[] = $a[$i][$j];
            }
        } else {
            die('Not a array!');
        }
    }
    return $r;
}
//test
print_r(t(range(1,4),range(1,4),range(1,4)));
echo '<br/>';
$a = array_merge(range(1,4),range(1,4),range(1,4));
print_r($a);

Guess you like

Origin blog.csdn.net/qq_42565994/article/details/102775128