通过有选择地取消设置值来过滤数组数组

OK, so I have : an array(a) of arrays(b) of arrays(c).

I'm trying to iterate through the array and unset (or to be precise delete) all arrays at level 'c', with less than 3 items.

How would you go about it?

I've tried every possible use of unset but I still can't the result I need.

foreach ($data as $a=>&$data_section)
{
    foreach ((array)$data_section as $b=>$pattern)
    {
        if (count((array)$pattern)<3) { unset($data_section[$b]); }
    }
}

This one gives an error :

Fatal error: Cannot unset string offsets

Why not just use array_filter.

php 5.3+ syntax

$data = array_filter($data, function($a){ return count($a) >2; });

pre php 5.3

function countGreaterThanTwo($a){ return count($a) >2; };
$data = array_filter($data, "countGreaterThanTwo");

So in your above example you would do

foreach ($data as $a=>&$data_section)
{
    foreach ($data_section as $b=>&$pattern)
    {
        $pattern = array_filter($pattern, function($a){ return count($a) >2; });
    }
}