06-27-2009, 09:29 PM
|
#4 (permalink)
|
|
The Acquainted
Join Date: Aug 2008
Posts: 158
Thanks: 8
|
array_splice is used to replace content and it doesn't throw an exception, so there is no need to put it on a try-catch block.
to delete an element (the value and the index too) you can use this:
PHP Code:
$arr = array('4', 'sdf', 'seoij', 'sodifj');
$arr = array_values(array_diff($arr, array('sdf')));
so you can make it a function:
PHP Code:
function array_remove($arr, $value){
return array_values(array_diff($arr, array($value)));
}
//then you can use this function like this
$arr = array('4', 'sdf', 'seoij', 'sodifj');
$arr = array_remove($arr, 'sdf');
print_r($arr);
/*
Array
(
[0] => '4'
[1] => 'soeij'
[2] => 'sodifj'
)
*/
Now in the example you gave, you are trying to apply this function to an array that is part of an object. I don't know how to help you on that since I don't know how the class of that object is structured.
But I hope this helps.
|
|
|
|