tonax99 Posted September 27, 2009 Share Posted September 27, 2009 Hi, I'm trying to figure out a way to search my array for any instance of 'images/smilies/' and remove that key from the array. I tried using search_array but it seems it only looks for exact matches, which wont work because the key will have 'images/smilies/rofl.gif' for example. here's an example of my array output. it's a multidimensional array so these are the results of my print_r (imgmatches[1]); Array ( [0] => http://i25.photobucket.com/albums/c62/becominglucid/Snapshot_20090529.jpg ) <br>Array ( [0] => images/smilies/frown.gif ) <br>Array ( [0] => http://i25.photobucket.com/albums/c62/becominglucid/Snapshot_20090529_7.jpg [1] => images/smilies/frown.gif ) it seems so simple but my knowledge is pretty limited Link to comment https://forums.phpfreaks.com/topic/175657-searching-array/ Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Try this: <?php $arr = Array("images/smilies/rofl.gif", "don't remove", Array("images/smilies/something.gif", "don't remove", "don't remove")); function removeRec(&$arr) { foreach($arr as $key => &$part) { if(is_array($part)) removeRec($part); else if(!stristr($part, "images/smilies") === false) unset($arr[$key]); } } echo "<pre>"; print_r($arr); removeRec($arr); print_r($arr); echo "</pre>"; ?> Output: Array ( [0] => images/smilies/rofl.gif [1] => don't remove [2] => Array ( [0] => images/smilies/something.gif [1] => don't remove [2] => don't remove ) ) Array ( [1] => don't remove [2] => Array ( [1] => don't remove [2] => don't remove ) ) Link to comment https://forums.phpfreaks.com/topic/175657-searching-array/#findComment-925593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.