Posted By

svenito on 09/29/09


Tagged

array remove Value


Versions (?)

Remove value from array


 / Published in: PHP
 

Remove $value from $array

  1. $new_data = explode(',',str_replace($value . ',' , '' , (join(',',$array))));

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: svenito on September 30, 2009

To get around the problem if the last element needs to be removed (issue due to the missing comma at the end) you can use regular expressions:

// make sure to escape $patterntext as required $pattern = "/,*$patterntext,*/"; $new_array = explode(',', preg_replace($pattern, '' , (join(',',$array))));

You need to login to post a comment.