quickly fill an array

i’ve been wondering what’s the quickest way to fill an array with a constant value? sometimes the code is necessary. for example, i have X number of items in an array and i wish to put them evenly into an table. to call another function, i need to pass in an array of values and an array of table width. well in my case, i just need to fill an array for table width with something like

$table_width = array('50%', '50%');

here’s my code to fill an array assuming $num_cols contains the number X.
$dummy = range(0, $num_cols - 1); foreach($dummy as $val) { $width_per[$val] = round(100/$num_cols)."%"; }
Is there a faster way to do this?


1 Comment Leave a Comment

July 6th, 2005 at 6:27 pm

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: