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. Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 ) ) Quote Link to comment Share on other sites More sharing options...
aquadeluxe Posted May 3, 2008 Author Share Posted May 3, 2008 Thank you! It worked perfect! 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.