subhomoy Posted May 20, 2014 Share Posted May 20, 2014 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 ) )); Quote Link to comment https://forums.phpfreaks.com/topic/288618-add-data-to-a-multidimentional-array/ Share on other sites More sharing options...
Barand Posted May 20, 2014 Share Posted May 20, 2014 (edited) 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 May 20, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/288618-add-data-to-a-multidimentional-array/#findComment-1480160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.