如何在数组中删除超过15个字符的所有元素

I want to delete in an array (it's a very big array) all element with more than 15 characters. What is the best way (in performance) to do this?

Use array_filter() with a callback function:

$new = array_filter($array, function($elem) {
    return strlen($elem) <= 15;
});

This is also possible with a normal foreach loop:

foreach ($array as $key => $value) {
    if (strlen($value) > 15) {
        unset($array[$key]);
    }
}

Looking to this problem through algorithmic aspect you definitly have to go through array and check size of characters in array. If size is bigger than 15 you have to delete the element. Minimal complexity is O(n) = n on unsorted array. You should give us some code and language you are working in.

How about:

foreach($arr as $key => $val)
{
    if(strlen($val) > 15)
    {
        unset($arr[$key]);
    }
}

array_values($arr);

I would just go with:

$filteredArray = array_filter($array, function($item){

  return strlen($item) < 15;

});

DEMO LIVE: https://eval.in/86391

I have done it for 2D array.

<?php
$arr = array(0=>array(0=>"1111111111","1"=>"22222222222222222"),array(0=>"111111111111111111",1=>"14554545454"));
echo "BEFORE";
print_r($arr);
for($j =0; $j < count($arr);$j++){
 foreach($arr[$j] as $k => $v){
     if( strlen($arr[$j][$k]) > 15){
       unset($arr[$j][$k]);
     }
 }
}

echo "AFTER";
print_r($arr);

For 1D array:

$arr2 = array(0=>"1111111111","1"=>"22222222222222222");
echo "BEFORE";
print_r($arr2);
 foreach($arr2 as $k => $v){
     if( strlen($arr2[$k]) > 15){
       unset($arr2[$k]);
     }

}

echo "AFTER";
print_r($arr2);