Jump to content

array help.


jamesxg1

Recommended Posts

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

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

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.