array_fill.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // $Id: array_fill.php,v 1.1 2007/07/02 04:19:55 terrafrost Exp $
  3. /**
  4. * Replace array_fill()
  5. *
  6. * @category PHP
  7. * @package PHP_Compat
  8. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  9. * @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
  10. * @link http://php.net/function.array_fill
  11. * @author Jim Wigginton <terrafrost@php.net>
  12. * @version $Revision: 1.1 $
  13. * @since PHP 4.2.0
  14. */
  15. function php_compat_array_fill($start_index, $num, $value)
  16. {
  17. if ($num <= 0) {
  18. user_error('array_fill(): Number of elements must be positive', E_USER_WARNING);
  19. return false;
  20. }
  21. $temp = array();
  22. $end_index = $start_index + $num;
  23. for ($i = (int) $start_index; $i < $end_index; $i++) {
  24. $temp[$i] = $value;
  25. }
  26. return $temp;
  27. }
  28. // Define
  29. if (!function_exists('array_fill')) {
  30. function array_fill($start_index, $num, $value)
  31. {
  32. return php_compat_array_fill($start_index, $num, $value);
  33. }
  34. }