aquadeluxe Posted May 3, 2008 Share Posted May 3, 2008 I have a script that will insert array('game' => 'value') into an array that doesn't have game already in it. Array ( [codelist] => Array ( [name] => Codelist name ) ) But when I use the command array_splice($result['codelist'], 1, 0, $gamearray) It just gives this result Array ( [codelist] => Array ( [name] => Codelist name [0] => value ) ) This is bugging me very badly; I have tried a lot of different array functions, but none of them seem to work. If any of you could help, I would be very thankful. Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/ Share on other sites More sharing options...
Aeglos Posted May 3, 2008 Share Posted May 3, 2008 maybe array_merge() ? array_merge($result['codelist'], $gamearray); Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/#findComment-532309 Share on other sites More sharing options...
Barand Posted May 3, 2008 Share Posted May 3, 2008 or $myarray['codelist']['game'] = $value; Depends how you want your array to be structured. Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/#findComment-532322 Share on other sites More sharing options...
aquadeluxe Posted May 3, 2008 Author Share Posted May 3, 2008 maybe array_merge() ? array_merge($result['codelist'], $gamearray); That didn't work. It would just return the $result array without adding $gamearray into it. @Barand: I don't know how i would use that. Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/#findComment-532441 Share on other sites More sharing options...
Barand Posted May 3, 2008 Share Posted May 3, 2008 <?php /******************************** * your array *********************************/ $result = array ( 'codelist' => array ('name' => 'Codelist name') ); /******************************** * my code *********************************/ $result['codelist']['game'] = 'value'; /******************************** * the result *********************************/ echo '<pre>', print_r($result, true), '</pre>'; ?> gives --> Array ( [codelist] => Array ( [name] => Codelist name [game] => value ) ) Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/#findComment-532476 Share on other sites More sharing options...
aquadeluxe Posted May 3, 2008 Author Share Posted May 3, 2008 Thank you! It worked perfect! Link to comment https://forums.phpfreaks.com/topic/103973-solved-help-with-arrays/#findComment-532478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.