Remove an item from a PHP array

Given an array in PHP, I need to remove a specific element (if it exists in the array) from the array. The following is a pretty simple and elegant solution. I didn't use unset on purpose because you have to check for a integer result before you remove the item from the array.

$arr     = array('apple','banana','orange');
$new_arr = array_diff($arr, array('banana'));

print_r($new_arr);


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.238.235.248
To prevent spam please submit by clicking the kitten: