Jump to content


Photo

filling an array with all 0's


  • Please log in to reply
2 replies to this topic

#1 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 19 August 2006 - 09:14 AM

without the use of a for-loop.

Is there a built-in function for this? Like I know for strings, I can use str_repeat...but what about arrays?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 August 2006 - 09:31 AM

http://www.php.net/array_pad
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 19 August 2006 - 10:31 AM

<?php
$array = array_fill(0,9,'0');
?>

Will make ten keys with the value 0.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users