Jump to content

Alternative to array_push


Recommended Posts

hey there php freaks


i have a code snippet and it using array_push and i was just curious to find out if there is an another way to use an array the same way but without array_push




$super = array();
$supersuper = array();

Link to comment
Share on other sites

Try doing this:


// initialize the array
$newArray = array();
// set some values in variables
$tick = 1;
$tock = 2;
// stick em in the array
$newArray[] = $tick;
$newArray[] = $tock;

this will create the following aray

$newArray(1, 2);


thats about it. I would use array_push() though -> you can do alot more like pushing arrays into arrays... etc. Check php.net for more info on it

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.