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" Quote Link to comment 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"; Quote Link to comment 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']); } Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 ?????? Quote Link to comment 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 } } Quote Link to comment 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 Quote Link to comment 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.