TheJoey Posted May 18, 2010 Share Posted May 18, 2010 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 thanks $super = array(); $supersuper = array(); array_push($tick,tock); Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/ Share on other sites More sharing options...
bibby Posted May 18, 2010 Share Posted May 18, 2010 not many (any?) other languages support this, but you can use brackets with a key to push to the "next" available key. $a = array(); $a[] = 1; // key 0 $a[] = 2; // key 1 Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1059911 Share on other sites More sharing options...
TheJoey Posted May 18, 2010 Author Share Posted May 18, 2010 im sorry could u explain that a little more? or mabye use the tick tock example i have :)thanks Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1059913 Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 $tick[] =tock; Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1059932 Share on other sites More sharing options...
TheJoey Posted May 18, 2010 Author Share Posted May 18, 2010 so array($tick[]=tock) instead the push? Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1060070 Share on other sites More sharing options...
BizLab Posted May 18, 2010 Share Posted May 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1060083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.