jamesxg1 Posted February 27, 2010 Share Posted February 27, 2010 Hiya peeps! I was wondering how I would search and multi-dimensional array for a specific value then replace that value with something else EG. array('ITEMONE' => 'VALUEONE', 'ITEMTWO' => 'VALUETWO'); // if value == VALUETWO replace with Hiya so the array would look like this after. array('ITEMONE' => 'VALUEONE', 'ITEMTWO' => 'Hiya'); Many many thanks, James. Link to comment https://forums.phpfreaks.com/topic/193531-array-help/ Share on other sites More sharing options...
jamesxg1 Posted February 27, 2010 Author Share Posted February 27, 2010 B to the U to the M to the P . Link to comment https://forums.phpfreaks.com/topic/193531-array-help/#findComment-1018822 Share on other sites More sharing options...
greatstar00 Posted February 27, 2010 Share Posted February 27, 2010 you could use foreach inside a recursive function this recursive function will handle any dimention of array, no matter 2d,3d, or 199999 d function search_value($arr){ foreach($arr as $key=>$value){ if(is_array($value)){ search_value($value); }else{ if($value==$specific_value){ //do your stuff } } } } Link to comment https://forums.phpfreaks.com/topic/193531-array-help/#findComment-1018823 Share on other sites More sharing options...
jamesxg1 Posted February 27, 2010 Author Share Posted February 27, 2010 Nice, worked like a charm there mate. Cheers for that! Many thanks James. Link to comment https://forums.phpfreaks.com/topic/193531-array-help/#findComment-1018825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.