note 17548 deleted from function.array-splice by jimw

From: Date: Thu, 20 Dec 2001 23:52:30 +0000
Subject: note 17548 deleted from function.array-splice by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23610@lists.php.net to get a copy of this message
I have doubts this will be usefull to others, but I'll try anyway ;)<BR><BR>I had an array containing a couple hundred values, but only few of them were other than zero and they were spread across the array. I wanted to generate a graph from it, which would directly connect all the non-zero values (ignoring the zero-values). Since the graph-software didn't do this, I wrote this. I'm sure it has bugs and eats cpu, but I don't know of a better way. here we go: <BR><BR> $i = 0; $j = 1; $k = 0; while($i < sizeof($array)) { if($array[$i]==0) { $zerolength[$k] = $j; $j++; } else { $nonzero[] = $array[$i]; $j = 1;$k++; } $i++; } for($i=0; $i <= sizeof($zerolength); $i++) { for($j=1; $j <= $zerolength[$i]; $j++) { $array[$j+$start-1] = (($nonzero[$i]-$nonzero[$i-1]) / ($zerolength[$i]+1)*($j))+$nonzero[$i-1]; } $start += $j; }

« previous php.notes (#23610) next »