PHP - Appending to array within a loop -


how append elements array within loop? example, using library render graph.

i wish add values graph so:

$data = array();  ($x=0; $x<=50; $x++) {     $data["00:".x] = rand(-10, 30); } 

so in theory should have elements "00:00", "00:01", "00:02" etc. random number value. however, library not render graph.

i'm guessing it's because don't understand php enough. how go trying achieve this?

you're missing leading zeros values of $x 0 through 9. you're missing dollar sign before variable $x:

for ($x=0; $x<=50; $x++) {     $data["00:".str_pad($x, 2, "0", str_pad_left)] = rand(-10, 30); } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -