Peter Chimp
Peter Chimp

Reputation: 137

Change Array Value

I have simple questions, How to change text if id = cur_three from array below ?

$arr = array(
    'id' => 'curr',
    'lists' => array(
        array(
            'id' => 'cur_one',
            'text' => 'Dollar', 
        ),                  
        array(
            'id' => 'cur_two',
            'text' => 'Euro',   
        ),
        array(
            'id' => 'cur_three',
            'text' => 'Peso',   
        ), 
    )
);

Thank you very much...

Upvotes: 0

Views: 34

Answers (2)

Abhishek Saha
Abhishek Saha

Reputation: 2564

Sure. Like this:

foreach($arr['lists'] as $key => $child) {

    if($child['id'] == 'cur_three') {
        $arr['lists'][$key]['text'] = "INR";
    }

}

Upvotes: 0

Tyr
Tyr

Reputation: 2810

Something simple:

foreach($arr['lists'] as $subArr) {
    if ($subArr['id'] == 'cur_three') {
        $subArr['text'] = 'not Peso';
    }
}

Upvotes: 1

Related Questions