Delete a value from comma separated list
Delete a user id from Php Comma separated values array saved in MySQL.
Use array_search function to delete the user id and it will delete the user id from the comma separated values with the help of unset function.
Demo – Delete a value from comma separated list
<?php $user_ids = "11,12,13,14,15,16,17,18,19,20"; $user_id_to_delete = 15; echo "User ID's before delete :" . $user_ids . "\n"; $array_of_user_ids = explode(",",$user_ids); $user_id_delete_key = array_search($user_id_to_delete,$array_of_user_ids); unset($array_of_user_ids[$user_id_delete_key]); $new_user_ids = implode(",",$array_of_user_ids); echo "User ID's after delete :" . $new_user_ids . "\n"; ?>