supernova.surfer Posted May 29, 2008 Share Posted May 29, 2008 Hello i need help making an array with these parameters but i dont know the syntax to use $x = 30 i need $x to be the 30'th value in the array called lets say $array1 , but i need the first 29 values to be empty strings like " " . so basically everytime i have different values for $x the array should get constructed accordingly with $x-1 number of " " values . would appreciate help with this construct ..thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 29, 2008 Share Posted May 29, 2008 Sounds pretty inefficient to fill up an array with empty values, what are you using it for? There should be a better solution. This will do it nonetheless: <?php $x = 30; $array1 = array_fill(1, $x - 1, ''); $array1[$x] = $x; echo '<pre>'; print_r($array1); echo '</pre>'; ?> Output: Array ( [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => [20] => [21] => [22] => [23] => [24] => [25] => [26] => [27] => [28] => [29] => [30] => 30 ) Quote Link to comment Share on other sites More sharing options...
supernova.surfer Posted May 29, 2008 Author Share Posted May 29, 2008 Hello , Thanks for the reply ... i'm planning to use jpgraph for a application the following is example code include ("../jpgraph.php"); include ("../jpgraph_scatter.php"); $datay = array(30,40,50); $graph = new Graph(300,200,"auto"); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(40,40,40,40); $graph->title->Set("Simple mpuls plot"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $sp1 = new ScatterPlot($datay); $sp1->mark->SetType(MARK_SQUARE); $sp1->SetImpuls(); $graph->Add($sp1); $graph->Stroke() i need only 3 values on the x-axis ..but if i use the above ...the values of 30,40,50 (y-scale) ...will be plotted at positions 1,2 and 3 i need them to be plotted at notch 30,40,50 Respectively ...i'll try and be as clear as possible..i hope i am. If i add 30 empty values in the array then my "bar" on my bar plot gets plotted like i want on the 30'th point on the x-scale Quote Link to comment Share on other sites More sharing options...
supernova.surfer Posted May 29, 2008 Author Share Posted May 29, 2008 ..will post "there" too but... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.