ProblemHelpPlease Posted January 13, 2011 Share Posted January 13, 2011 I have an array as belowArray ( [0] => 9632155000058 [1] => 9632155000157 [2] => 9632155000195 [3] => 9632155000034 [4] => 9632155000201 [5] => 9632155000171 )I want to search the array for a specific number (9632155000195 for example) and remove it from the array so that the array would then look likeArray ( [0] => 9632155000058 [1] => 9632155000157 [2] => 9632155000034 [3] => 9632155000201 [4] => 9632155000171 )The array is dynamically created so the number are not always the same or in the same position and the array can be any length.What is the most efficent way to do this. Link to comment Share on other sites More sharing options...
ShadowMage Posted January 13, 2011 Share Posted January 13, 2011 You can use array_search to find the value and array_splice to remove it. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted January 13, 2011 Author Share Posted January 13, 2011 I have ended up using$mynumber = "9632155000195";$myarray = array_diff($myarray, array($mynumber));It seemed the least amount of code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.