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); 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 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 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; 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? 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 Link to comment https://forums.phpfreaks.com/topic/202126-alternative-to-array_push/#findComment-1060083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.