Jump to content

add data to a multidimentional array


subhomoy

Recommended Posts

Hello every body i have a array like this

Array
(
    [19/5/14] => Array
        (
            [94-DE-80-28-CF-BC] => Array
                (
                    [7] => Array
                        (
                            [qax] => 1
                        )

                )
          }
}

I want to add new array under the [94-DE-80-28-CF-BC] => Array..

 

I am doing code but what it does it overrides the full array inside that array and create a new one...

 

The code i've used is


                   |
array_push( $vis[$date][$macp], array(
				"$id"=>array(
				    "$country"=>1
				)
			));
Link to comment
https://forums.phpfreaks.com/topic/288618-add-data-to-a-multidimentional-array/
Share on other sites

When I run your code

$vis = array
(
    '19/5/14' => array
        (
            '94-DE-80-28-CF-BC' => Array
                (
                    7 => Array
                        (
                            'qax'=> 1
                        )

                )
          )
);
$date = '19/5/14';
$macp = '94-DE-80-28-CF-BC';
$id = 3;                                        // arbitrary test value
$country = 'uk';                                // arbitrary test value
array_push( $vis[$date][$macp], array(
                "$id"=>array(
                    "$country"=>1
                )
            ));

Nothing gets overridden, I get

Array
(
    [19/5/14] => Array
        (
            [94-DE-80-28-CF-BC] => Array
                (
                    [7] => Array
                        (
                            [qax] => 1
                        )

                    [8] => Array
                        (
                            [3] => Array
                                (
                                    [uk] => 1
                                )

                        )

                )

        )

)

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.