jonaofarc Posted March 17, 2009 Share Posted March 17, 2009 $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 Link to comment https://forums.phpfreaks.com/topic/149903-how-to-i-replace-a-value-in-a-two-dimensional-array-i-have-an-example/ Share on other sites More sharing options...
samshel Posted March 18, 2009 Share Posted March 18, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/149903-how-to-i-replace-a-value-in-a-two-dimensional-array-i-have-an-example/#findComment-787261 Share on other sites More sharing options...
jonaofarc Posted March 18, 2009 Author Share Posted March 18, 2009 thank you Link to comment https://forums.phpfreaks.com/topic/149903-how-to-i-replace-a-value-in-a-two-dimensional-array-i-have-an-example/#findComment-787272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.