MrAdam Posted January 5, 2007 Share Posted January 5, 2007 hey all!i've been on with this for past half hour, and im a bit frustrated now!i have a variable which contains an id. In some cases the id may be repeated (multiple times), and a comma inbetween the id's. for example: "33" OR "33,33" OR "33,33,33" etc.im trying to create a simple function to remove just one of the id's: so, "33,33" becomes "33".my question is; how do I do it ?! -Thanks! Link to comment Share on other sites More sharing options...
jlhaslip Posted January 6, 2007 Share Posted January 6, 2007 http://www.php.net check out the function for array_unique()http://ca.php.net/manual/en/function.array-unique.php Link to comment Share on other sites More sharing options...
MrAdam Posted January 6, 2007 Author Share Posted January 6, 2007 thanks-but not quite what im looking for. Link to comment Share on other sites More sharing options...
jlhaslip Posted January 6, 2007 Share Posted January 6, 2007 Explode the variable into an array and then use the array_unique () to reduce it down to a single occurence.An alternate would be to explode the variable into an array and use the array(0) element. Link to comment Share on other sites More sharing options...
MrAdam Posted January 6, 2007 Author Share Posted January 6, 2007 no no, thing is, i don't want the unique.. i want to get rid of just one of the identical id's .. so if the variable contained "33,33,33,33" .. i want to be left with "33,33,33". Link to comment Share on other sites More sharing options...
MrAdam Posted January 6, 2007 Author Share Posted January 6, 2007 i managed to sort it: $id = "72"; // usually i would have run some statements to be left with the array[x] matching my id$test = Array();$test[0] = "72,72,72";$len = strlen($id) + 1; // length of ID plus 1 more for the comma$rem = strlen($test[0]) - $len; // the remainder from length of the array[x] minus $len$test[0] = substr($test[0],$len,$rem); // use substr() to only select after the first id, effectivelly, only removing one of the IDs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now