note 38093 deleted from ref.array by kennyt

From: Date: Tue, 27 Jan 2004 03:49:27 +0000
Subject: note 38093 deleted from ref.array by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64224@lists.php.net to get a copy of this message
Note Submitter: xntx@msn.com ---- This function removes "blank" (null) elements from the array provided. <?php function clear_array ( $a ) { if ( $a !== array() ) { $b = array(); foreach ( $a as $key => $value ) { if ( is_array ( $value ) ) { if ( limpiar ( $value ) !== false ) { $b[$key] = clear_array ( $value ); } } elseif ( $value !== '' ) { $b[$key] = $value; } } if ( $b !== array() ) { return $b; } else { return false; } } else { return false; } } ?> for example, some array as this: <?php $a = array ( "sihay" => 'valor', "tambien" => 'otrovalor', "subarray" => array ( "cosa" => 'aqui', "nada" => ''), "otrosub" => array() ); ?> using <?php $b = clear_array ( $a ); ?> will be converted into: <?php $b == array ( "sihay" => 'valor', "tambien" => 'otrovalor', "subarray" => array ( "cosa" => 'aqui') ); ?>

« previous php.notes (#64224) next »