Jump to content

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
                                )

                        )

                )

        )

)
Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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