Answers for "remove all keys that have values of n/a, -, or empty strings. if one of these values appear in an array, remove that single item from the array in php."

PHP
11

php array remove empty values

<?php
$arr = array('1', '', '2', '3', '0');
// Incorrect:
print_r(array_filter($arr));
// Correct:
print_r(array_filter($arr, 'strlen'));
//Custom
print_r(array_filter($arr, function ($val) {if ($val > 0) {return true;} else {return false;}}));
Posted by: Guest on July-07-2020
1

how to remove keys in subarray php

print_r(deep_delete_keys($arr,'country'));

function deep_delete_keys($arr, $keys) {
    if (!is_array($keys)) $keys = array($keys);
    $filteredArr = array_diff_key( $arr, array_flip( $keys ) );
    foreach ($filteredArr as &$val) {
        if (is_array($val)) {
            $val = deep_delete_keys($val, $keys);
        }
    }
    return $filteredArr;
}
Posted by: Guest on March-28-2020
0

php remove empty values from array

$array = array_filter($array, function($a) {
    return trim($a) !== "";
});
Posted by: Guest on December-25-2020

Code answers related to "remove all keys that have values of n/a, -, or empty strings. if one of these values appear in an array, remove that single item from the array in php."

Browse Popular Code Answers by Language