note 106833 deleted from function.array-fill-keys by danbrown

From: Date: Sun, 11 Dec 2011 19:10:50 +0000
Subject: note 106833 deleted from function.array-fill-keys by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185028@lists.php.net to get a copy of this message
Note Submitter: comments at htmlcompressor dot com ---- I needed a PHP4 compatible version which behaves as expected from the PHP5 version. I tried the ones contributed by other users here but they do fail to comply, so I made the following function: <?php if (!function_exists('array_fill_keys')) { function array_fill_keys($keys, $value) { if (!is_array($keys)) { trigger_error('array_fill_keys() expects parameter 1 to be array, ' . gettype($keys) . ' given', E_USER_WARNING); return; } $filled_array = array(); foreach($keys as $key) { $filled_array[$key] = $value; } return $filled_array; } } ?>

« previous php.notes (#185028) next »