简体   繁体   中英

Replacing multi-array values in PHP

I'm currently setting up a guild website, on one of the pages I'm fetching information from an off-site resource which returns the requested data in an array, looking like this:

[0] => Array
(
    [character] => Array
        (
            [name] => Name
            [realm] => Server
            [battlegroup] => Battlegroun Name
            [class] => int
            [race] => int
            [gender] => int
            [level] => int
            [achievementPoints] => int
            [thumbnail] => image
            [thumbnailURL] => url
        )
    [rank] => int
)
...

I have to admit, it's been a good while since I even dwelled in to PHP last, and I'm absolutely dumbfolded when it comes to translating values inside the array. (I knew once!)

What I basically want to achieve was to "translate", for example $arr['character']['gender'] from it's integer value to values I've set from another array.

$gender = array(0 => 'M', 1 => 'F');

I've tried a few solutions already but, I've come up empty handed. I'm hoping some of you guys have any pointers for me.

Thanks in advance, nontheless!

Hi You can try sample code given below..

foreach($arr As $index=>$arrs{
    $arrs[$index]['character']['gender'] = $gender[$arrs[$index]['character']['gender']];
}

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM