Jump to content

[SOLVED] Help with arrays


aquadeluxe

Recommended Posts

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

<?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
        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.