own sabzh. We need to do this so that there are no empty elements left after that.

ps Perhaps the topic is already rising for the 100th time, but I didn’t have the function at hand, in Google there are mostly one-dimensional examples.

Yes, and also, the key is unknown in advance, you guessed it.

The array has the form $ arr = array ('key1' => array ('foo' => 'znachenie'), .. etc.

  • one
    And what about next? .... - AseN

2 answers 2

// Функция для удаление элементов из массива $array по значению $value с рекурсивным спуском function deleteItem( &$array, $value ) { foreach( $array as $key => $val ){ if( is_array($val) ){ deleteItem($array[$key], $value); }elseif( $val===$value ){ unset($array[$key]); } } } // Пример: $arr = array( 'key1'=>'value1', 'key2'=>array( 'key21'=>'value21', 'key22'=>'value22', 'key23'=>'value23', ), 'key3'=>'value3', ); deleteItem($arr, 'value22'); 

    If you understand the problem correctly, you must use a recursive array traversal with checking for empty () . In the recursive function, the element is passed by reference, and in the case of an empty value, delete it.