nadeemshafi9 Posted April 7, 2009 Share Posted April 7, 2009 hi i define an array array("ext" => "21005", "ddi" => "01512322292") and later get it as $array how do i add a new index to this array like "total" => "20" Link to comment https://forums.phpfreaks.com/topic/152965-array-help/ Share on other sites More sharing options...
Mark Baker Posted April 7, 2009 Share Posted April 7, 2009 $array = array("ext" => "21005", "ddi" => "01512322292"); $array["total"] = "20"; Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803360 Share on other sites More sharing options...
nadeemshafi9 Posted April 7, 2009 Author Share Posted April 7, 2009 sorry to be annoying mate but thats what i tried its not working $srcArray = array( array("ext" => "FAKE", "ddi" => "564"), array("ext" => "FAKE", "ddi" => "345345"), ); foreach($srcArray as $src){ $src['count'] = $this->countLoggsFor($src['ddi']); } Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803371 Share on other sites More sharing options...
JasonLewis Posted April 7, 2009 Share Posted April 7, 2009 What you need to do is basically "link" the $src variable to the original. This is done by using an ampersand. Try this: foreach($srcArray as &$src){ Now that references the original variable and so any editing should be done to the original. Give it a shot. Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803375 Share on other sites More sharing options...
nadeemshafi9 Posted April 7, 2009 Author Share Posted April 7, 2009 sorry my bad seems like i have it now how i needed it with your help foreach($srcArray as $k => $src){ $srcArray[$k]['count'] = $this->countLoggsFor($srcArray[$k]['ddi'] ); } CAN SOMONE TELL ME HOW TO ACCESS COUNT IN THIS >>>>> Array ( [0] => Array ( [`count`] => 568 [src] => 380 ) ) THANKS Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803391 Share on other sites More sharing options...
nadeemshafi9 Posted April 7, 2009 Author Share Posted April 7, 2009 What you need to do is basically "link" the $src variable to the original. This is done by using an ampersand. Try this: foreach($srcArray as &$src){ Now that references the original variable and so any editing should be done to the original. Give it a shot. is this similar to using the key - val aray[key]['count'] = $count ?????? Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803493 Share on other sites More sharing options...
wrathican Posted April 7, 2009 Share Posted April 7, 2009 my advice would be to read up on multi dimensional arrays for you your problem, you have an array containing arrays: $array = array(); $array['one'] = array(); $array['one']['two'] = 'hello world'; var_dump($array); that should print something like Array(){ 'one' => Array(){ 'two' => hello world } } Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-803498 Share on other sites More sharing options...
nadeemshafi9 Posted April 14, 2009 Author Share Posted April 14, 2009 $array = array("ext" => "21005", "ddi" => "01512322292"); $array["total"] = "20"; this does work thanks Link to comment https://forums.phpfreaks.com/topic/152965-array-help/#findComment-809726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.