I have post data that looks like this:
array(2) {
["ui"]=> array(1) {
["menu"]=> array(3) {
["button1"]=> string(8) "Press me"
["button2"]=> string(9) "Tickle me"
["button3"]=> string(0) ""
}
}
["messages"]=> array(1) {
["status"]=> array(2) {
["error"]=> string(0) ""
["success"]=> string(0) ""
}
}
}
I want to remove all key, value pairs that have an empty value to get a result like this:
array(1) {
["ui"]=> array(1) {
["menu"]=> array(2) {
["button1"]=> string(8) "Press me"
["button2"]=> string(9) "Tickle me"
}
}
}
So I implemented this recursive function:
function clear_empty_array_values($array){
foreach($array as $key => $value){
if (is_array($value)){
clear_empty_array_values($value);
}else{
if (empty($value)){
unset($array[$key]);
}
}
}
}
But when I call this function on my array:
clear_empty_array_values($my_array);
I get the same result as before calling the method.
Can you see what is wrong?