note 111526 modified in function.array-replace by danbrown

From: Date: Mon, 04 Mar 2013 17:44:21 +0000
Subject: note 111526 modified in function.array-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193816@lists.php.net to get a copy of this message
Function that replace empty vals with $replace = "N/A" Function parametters : $array as array => array to be parsed $replace as string => replace <?php function rep_empty_vals_arr($array,$replace = "N/A") { $returned_array = array(); foreach($array as $k=>$v) { if(is_array($v)) { $returned_array[$k] = rep_empty_vals_arr($v,$replace); } if(empty($v)) { $returned_array[$k] = $replace; }else{ $returned_array[$k] = $v; } } return $returned_array; } ?> --was-- Function that replace empty vals with $replace = "N/A" Function parametters : $array as array => array to be parsed $replace as string => replace function rep_empty_vals_arr($array,$replace = "N/A") { $returned_array = array(); foreach($array as $k=>$v) { if(is_array($v)) { $returned_array[$k] = rep_empty_vals_arr($v,$replace); } if(empty($v)) { $returned_array[$k] = $replace; }else{ $returned_array[$k] = $v; } } return $returned_array; } http://php.net/manual/en/function.array-replace.php

« previous php.notes (#193816) next »