note 86273 added to function.array-push

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
A function which mimics push() from perl, perl lets you push an array to an array: push(@array, @array2, @array3). This function mimics that behaviour.

<?php

function array_push_array(&$arr) {
    $args = func_get_args();
    array_shift($args);

    if (!is_array($arr)) {
        trigger_error(sprintf("%s: Cannot perform push on something that isn't an array!", __FUNCTION__), E_USER_WARNING);
        return false;
    }

    foreach($args as $v) {
        if (is_array($v)) {
            if (count($v) > 0) {
                array_unshift($v, &$arr);
                call_user_func_array('array_push',  $v);
            }
        } else {
            $arr[] = $v;
        }
    }
    return count($arr);
}

$arr = array(0);
$arr2  = array(6,7,8);
printf("%s\n", array_push_array($arr, array(),array(1,2,3,4,5), $arr2));
print_r($arr);

# error.. 
$arr = "test";
printf("%s\n", array_push_array($arr, array(),array(1,2,3,4,5), $arr2));

?>
----
Server IP: 89.248.170.61
Probable Submitter: 85.144.160.165
----
Manual Page -- http://www.php.net/manual/en/function.array-push.php
Edit        -- https://master.php.net/note/edit/86273
Del: integrated  -- https://master.php.net/note/delete/86273/integrated
Del: useless     -- https://master.php.net/note/delete/86273/useless
Del: bad code    -- https://master.php.net/note/delete/86273/bad+code
Del: spam        -- https://master.php.net/note/delete/86273/spam
Del: non-english -- https://master.php.net/note/delete/86273/non-english
Del: in docs     -- https://master.php.net/note/delete/86273/in+docs
Del: other reasons-- https://master.php.net/note/delete/86273
Reject      -- https://master.php.net/note/reject/86273
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.