array_push in multidimensional array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

array_push in multidimensional array

Post by robster »

Hi all :)

I have this array pre-defined:

Code: Select all

$services_array2 = array(array(0,0));
I want to put data into it during a loop using array_push. I tried something like this and it didn't work (obviously ;)):

Code: Select all

array_push ( $services_array2, ($service_id, $service_price));
Does anyone know of a way I can get the $service_id and $service_price data into that array each time I move through the loop? I presumed array_push but am now unsure.

Thanks for your time :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$arr = array(array(0,0));

array_push( $arr, array(10, 12));

var_export( $arr );

Code: Select all

array (
  0 =>
  array (
    0 => 0,
    1 => 0,
  ),
  1 =>
  array (
    0 => 10,
    1 => 12,
  ),
)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

thank you thank you thank you! :)
Post Reply