note 115793 modified in function.array-fill by levim
| From: | levim@php.net | Date: | Thu, 20 Nov 2014 21:31:25 +0000 |
| Subject: | note 115793 modified in function.array-fill by levim | ||
| References: | 1 | Groups: | php.notes php.notes |
| Request: | Send a blank email to php-notes+get-200969@lists.php.net to get a copy of this message | ||
Before PHP 5.6, array_fill emits a warning if the argument $num is zero. This is a bit annoying if
you compute a desired array length. As a workaround, one can use array_pad, which is less strict.
I.e.
<?php
$desiredLength = 0;
// $noWorky = array_fill(0, $desiredLength, "a");
$worky = array_pad(array(), $desiredLength, "a");
?>
--was--
PHP emits a warning if array_fill's $num argument is zero. This is a bit annoying if you
compute a desired array length. As a workaround, one can use array_pad, which is less strict.
I.e.
<?php
$desiredLength = 0;
// $noWorky = array_fill(0, $desiredLength, "a");
$worky = array_pad(array(), $desiredLength, "a");
?>
http://php.net/manual/en/function.array-fill.php