Jump to content

how to i replace a value in a two dimensional array? I have an example


jonaofarc

Recommended Posts

$employees = array

(

"employee 1" => array

(

  "name" => "Dana",

  "title" => "Owner",

  "salary" => "$60,000",

),

 

"employee 2" => array

(

  "name" => "Matt",

  "title" => "Manager",

  "salary" => "$40,000",

),

 

"employee 3" => array

(

  "name" => "Susan",

  "title" => "Cashier",

  "salary" => "$30,000",

)

);

 

 

I want a simple loop that replaces anyone with the name dana to the color green

 

 

 

if(is_array($employees)) {
foreach($employees as $key=>$arremployee) {
   if(is_array($arremployee)) {
      foreach($arremployee as $innerkey=>$val) {
           if($innerkey == "name" && $val == "Dana") {
                  $employees[$key][$innerkey] = "<font color ='green'>Dana</font>";
           }
      } 
   }
}
}

not tested..

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.