avenged Posted April 20, 2006 Share Posted April 20, 2006 hello, was just wondering how I would be able to use str_replace to skip an index in an array if something is found in str_replace. I have a str_replace that checks an array for values in an array.[code]str_replace($array1, "", $array2);[/code]it searches array2 with values from array1, and i was wondering, if it finds a match, instead of it replacing it with a space, how do i replace it with nothing, as in the array returned wont even have an index with anything in it with that?. say i am searching an array with values:array('1', '2', '3');and i want to search it from the values contained in this array:array('1');so, obviously, it would return a match with this array:array('', '2', '3');How would I replace the match with nothing, so it would return an array like this:array('2', '3');??Thanks! Quote Link to comment Share on other sites More sharing options...
slashemail Posted April 20, 2006 Share Posted April 20, 2006 One clear cut solution would be.Get the size of the array, Loop through the aray and replace each instance in the array.[code]for ($i=0;$i<sizeof($array1);$i++){ if ($array1[$i] == "What ever") #strcmp could also be used { $array1[$i] = ""; #Use any value }}[/code]You can use your own logic to read the array & replace the occurences found within.Hope this will puts some light. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.