I have array:
Array
(
[5] => Array
(
[0] => 19
[1] => 18
)
[6] => Array
(
[0] => 28
)
)
And I'm trying to delete element by value using my function:
function removeElementWithValue($obj, $delete_value){
if (!empty($obj->field)) {
foreach($obj->field as $key =>$value){
if (!empty($value)) {
foreach($value as $k=>$v){
if($v == $delete_value){
$obj->field[$key][$k] = '';
}
}
}
}
}
return urldecode(http_build_query($obj->field));
}
echo removeElementWithValue($request, '19');
After operation above I have: 5[0]=&5[1]=18&6[0]=28; // Right!!!
echo removeElementWithValue($request, '18');
After operation above I have: 5[0]=&5[1]=&6[0]=28; // Wrong ???
But my expected result after second operation is:
5[0]=19&5[1]=&6[0]=28;
Where is my mistake? Thanks!
StdClass Objectsand you are passingarray. why ?