sspoke Posted June 2, 2010 Share Posted June 2, 2010 Simple question how do I append to a 2 dimensional Array i dont care just want to know how? Thanks <?php $shop = array( array( Title => "rose", Price => 1.25, Number => 15 ), array( Title => "daisy", Price => 0.75, Number => 25, ), array( Title => "orchid", Price => 1.15, Number => 7 ) ); ?> If anyone who think's they dont understand my question i don't want when you print it out like.. print_r() to add a new array not just element to a existing array in arrays I want to insert a array of 3 elements into the master array of arrays. How do i do that? As well as unsetting but i guess unset($shop[0]) would delete the first array of 3 elements yes?. Link to comment https://forums.phpfreaks.com/topic/203645-simple-multidimensional-array-appending/ Share on other sites More sharing options...
sspoke Posted June 2, 2010 Author Share Posted June 2, 2010 I wasn't even clear in my question but I solved it myself array_merge is perfect for resetting key indexics //Powerleveling script for MMO gold farming profit <?php $shop = array( array("slevel"=>1, "elevel" => 50, "price" => 15.75 ), array( "slevel" => 3, "elevel" => 60, "price" => 25.50, ), array( "slevel" => 20, "elevel" => 60, "price" => 75.32 ) ); print_r($shop); unset($shop[1]); //deletes 2nd element print_r($shop); //shows 0,2 $shop = array_merge($shop); //fixes the key sorting problem yes!!! print_r($shop); //shows 0,1 =D now i can sort id's perfectly! $shop[] = array("slevel" => 55, "elevel" => 60, "price"=> 10.33); //adding new one. print_r($shop); //shows 0,1,2 perfecto ?> Link to comment https://forums.phpfreaks.com/topic/203645-simple-multidimensional-array-appending/#findComment-1066698 Share on other sites More sharing options...
kenrbnsn Posted June 2, 2010 Share Posted June 2, 2010 This is one way: <?php $shop[] = array('Title' =>'xyz', 'Price' => 0.01, 'Number' => 42); ?> BTW, the string indices should be in quotes (single or double). Ken Link to comment https://forums.phpfreaks.com/topic/203645-simple-multidimensional-array-appending/#findComment-1066700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.