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 ) )); 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 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 ) ) ) ) ) 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
Archived
This topic is now archived and is closed to further replies.