note 17548 added to function.array-splice

From: Date: Thu, 13 Dec 2001 17:20:51 +0000
Subject: note 17548 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-22587@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; } -- http://www.php.net/manual/en/function.array-splice.php http://master.php.net/manage/user-notes.php?action=edit+17548 http://master.php.net/manage/user-notes.php?action=delete+17548 http://master.php.net/manage/user-notes.php?action=reject+17548

« previous php.notes (#22587) next »