Jump to content

simple Multidimensional Array appending


sspoke

Recommended Posts

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

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.