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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -