Re: [PHP-DB] incrememnting an array
On Fri, 2002-09-20 at 16:49, John Coder wrote: > On Fri, 2002-09-20 at 05:41, Martin Adler wrote: > > > > I hope the little script bellow helps you > > > > greet > > Martin > > > > > $arr = array('a','b','c','d','e','f','g','h'); > > > > $arr2[] = $x = array_shift($arr); > > $arr2[] = $y = array_shift($arr); > > $arr2[] = $y; > > > > while($arr) > > { > > $arr2[] = $x.$y .= array_shift($arr); > > $arr2[] = $x.$y; > > } > > > > echo implode(',',$arr2); > > > > echo ''; > > print_r($arr2); > > echo ''; > > ?> > Unfortunately this concatates the numbers instead of summing them I need > it to sum them.even if I type cast it to int it still concatates them. > what I need is from the array: > array(0,23,2,15,1,14,1,43,22) > a new array having: > array(0,23,23,25,25,40,40,41,41,55,55,98,98,120) > think of angle and ) being the beginning 23 being the end then 23 being > the begging of an angle haveing 2 degress so I need it to go to 25 and > so forth. hope this explains it better. > Getting back to those that helped. I ende up splitting the arrays one for start and one for end. I then added 0 to start and subtracted the last from start. here is the code I ended up with: $a=array(); while($d=mysql_fetch_array($start_angle_query)) { $a[]=$d[0]; } //copies mysql_fetch_array into an array $b=array(); $b =$a; // make two arrays one for start of angle 2nd for end of angle $degree_adjuster=360/array_sum($b); //constant for circle array_unshift($a,0 ); // add 0 for start angle $start_angle=array(); // new array to hold values for start vector $end_angle=array(); //new array to hold values for end vector array_pop($a); //trim one array for start so numbers don't end on 360 while($a) //iterate till array is empty { array_push($start_angle,(end($start_angle)+ $a[0])); /*enter numbers in array $start_angle adding the last number in array and adding the first number from modified original array*/ array_shift($a);//delete first value of array } while($b) { array_push($end_angle,(end($end_angle)+$b[0])); array_shift($b); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] incrememnting an array
try this: \n"; print_r($arr4); echo "\n"; ?> "John Coder" <[EMAIL PROTECTED]> escribió en el mensaje 1032554996.1899.9.camel@linux">news:1032554996.1899.9.camel@linux... > On Fri, 2002-09-20 at 05:41, Martin Adler wrote: > > > > I hope the little script bellow helps you > > > > greet > > Martin > > > > > $arr = array('a','b','c','d','e','f','g','h'); > > > > $arr2[] = $x = array_shift($arr); > > $arr2[] = $y = array_shift($arr); > > $arr2[] = $y; > > > > while($arr) > > { > > $arr2[] = $x.$y .= array_shift($arr); > > $arr2[] = $x.$y; > > } > > > > echo implode(',',$arr2); > > > > echo ''; > > print_r($arr2); > > echo ''; > > ?> > Unfortunately this concatates the numbers instead of summing them I need > it to sum them.even if I type cast it to int it still concatates them. > what I need is from the array: > array(0,23,2,15,1,14,1,43,22) > a new array having: > array(0,23,23,25,25,40,40,41,41,55,55,98,98,120) > think of angle and ) being the beginning 23 being the end then 23 being > the begging of an angle haveing 2 degress so I need it to go to 25 and > so forth. hope this explains it better. > > > > - Original Message - > > From: "John Coder" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Friday, September 20, 2002 8:19 AM > > Subject: [PHP-DB] incrememnting an array > > > > > > hi all > > this is what I would like to do. I have a dynamically generated array from a > > database and I wnat to do a piechart from it . for example the array would > > hold (a,b,c,d,e,f,g,h) sometimes more sometimes less . I need to get the > > values of a,b,b,a+b,a+b,a+b+c,a+b+c,a+b+c+d, and son on these are for the > > values of the angles for the pie chart on imagefilledarc(). And for the life > > of me I can't figure out how to do it. > > > > any help would be greatly appreciated > > > > John Coder > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] incrememnting an array
On Fri, 2002-09-20 at 05:41, Martin Adler wrote: > > I hope the little script bellow helps you > > greet > Martin > > $arr = array('a','b','c','d','e','f','g','h'); > > $arr2[] = $x = array_shift($arr); > $arr2[] = $y = array_shift($arr); > $arr2[] = $y; > > while($arr) > { > $arr2[] = $x.$y .= array_shift($arr); > $arr2[] = $x.$y; > } > > echo implode(',',$arr2); > > echo ''; > print_r($arr2); > echo ''; > ?> Unfortunately this concatates the numbers instead of summing them I need it to sum them.even if I type cast it to int it still concatates them. what I need is from the array: array(0,23,2,15,1,14,1,43,22) a new array having: array(0,23,23,25,25,40,40,41,41,55,55,98,98,120) think of angle and ) being the beginning 23 being the end then 23 being the begging of an angle haveing 2 degress so I need it to go to 25 and so forth. hope this explains it better. > - Original Message - > From: "John Coder" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, September 20, 2002 8:19 AM > Subject: [PHP-DB] incrememnting an array > > > hi all > this is what I would like to do. I have a dynamically generated array from a > database and I wnat to do a piechart from it . for example the array would > hold (a,b,c,d,e,f,g,h) sometimes more sometimes less . I need to get the > values of a,b,b,a+b,a+b,a+b+c,a+b+c,a+b+c+d, and son on these are for the > values of the angles for the pie chart on imagefilledarc(). And for the life > of me I can't figure out how to do it. > > any help would be greatly appreciated > > John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] incrememnting an array
I hope the little script bellow helps you greet Martin '; print_r($arr2); echo ''; ?> - Original Message - From: "John Coder" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, September 20, 2002 8:19 AM Subject: [PHP-DB] incrememnting an array hi all this is what I would like to do. I have a dynamically generated array from a database and I wnat to do a piechart from it . for example the array would hold (a,b,c,d,e,f,g,h) sometimes more sometimes less . I need to get the values of a,b,b,a+b,a+b,a+b+c,a+b+c,a+b+c+d, and son on these are for the values of the angles for the pie chart on imagefilledarc(). And for the life of me I can't figure out how to do it. any help would be greatly appreciated John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php