Page 1 of 1

array_push in multidimensional array

Posted: Mon Mar 28, 2005 11:28 pm
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 :)

Posted: Tue Mar 29, 2005 5:18 am
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,
  ),
)

Posted: Tue Mar 29, 2005 5:45 pm
by robster
thank you thank you thank you! :)