jonniejoejonson Posted November 16, 2006 Share Posted November 16, 2006 Okay I have a fairly long and complicated (becuase I am new to scripting) piece of code. it is very close to working but it is giving me one strange reading. the final unset($aryHundreds); is not deleteing the array how I want. However if you test the array after the unset, it has deleted it. However I think it is a timming issue. As it seems to be giving me the results of all three lots of results. 1/ function A($origZip,$origLng,$origLat){//This runs function starter roughly 3 times.starter($origZip,$origLng,$origLat);}2/function starter($origZip,$origLng,$origLat){//This then runs function distance 1000 times, for each of the 3 times that starter has been run.distance($origZip1,$lon1,$lat1,$zip2,$lon2,$lat2);} function distance($origZip1,$lon1,$lat1,$zip2,$lon2,$lat2) { $distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180);print "<br>$origZip1.$distance";global $aryHundreds;global $counter;global $numberOfStatesToCompare;$counter++;if($distance<100){print $zip2."under 100";array_push($aryHundreds, $zip2);}if($numberOfStatesToCompare==$counter){$counter=0;$stringHundred='';for ($i=0;$i<count($aryHundreds);$i++) {$stringHundred.=$aryHundreds[$i].'|';}print 'markerHere:'.count($aryHundreds).'string'.$stringHundred;unset($aryHundreds);}//like i mentioned the only problem is that unset($aryHundreds) does not seem to be in the right place, as it needs to be//deleted before the second lot of function A is executed. Oddly all the results are correct, but just being repeated three times over by //the time the third lot of funcitn A is exectued.Thanks top any responders. jonnie Link to comment https://forums.phpfreaks.com/topic/27396-please-help-clear-array/ Share on other sites More sharing options...
jsladek Posted November 16, 2006 Share Posted November 16, 2006 probably not the best way but you could probably replace unset($aryHundreds);with $aryHundreds = array(); -RegardsJohn SladekAfter Rereading you post that might not work for you either.... Link to comment https://forums.phpfreaks.com/topic/27396-please-help-clear-array/#findComment-125304 Share on other sites More sharing options...
jonniejoejonson Posted November 16, 2006 Author Share Posted November 16, 2006 Thanks for the reply but it doesn't work either. It is strange becuase if you try and use the array after the unset within the function it has been deleted. However I assume that the other functions have executed the final function before it clears the array, however the output would suggest otehrwise. Anyone else any further ideas? Link to comment https://forums.phpfreaks.com/topic/27396-please-help-clear-array/#findComment-125342 Share on other sites More sharing options...
doni49 Posted November 16, 2006 Share Posted November 16, 2006 1) Without indenting, your code is very hard to follow so I copy/pasted it into my editor and did some indenting so that I could follow it.2) I don't understand how this is working--you're missing a curly brace (it's marked).3) Try putting the unset AFTER the if statement (it's marked). See what it does. I'm not sure.<?PHPfunction A($origZip,$origLng,$origLat){ //This runs function starter roughly 3 times. starter($origZip,$origLng,$origLat);}function starter($origZip,$origLng,$origLat){ //This then runs function distance 1000 times, for each of the 3 times that starter has been run. distance($origZip1,$lon1,$lat1,$zip2,$lon2,$lat2);}function distance($origZip1,$lon1,$lat1,$zip2,$lon2,$lat2) { $distance = (3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180); print " $origZip1.$distance"; global $aryHundreds; global $counter; global $numberOfStatesToCompare; $counter++; if($distance<100){ print $zip2."under 100"; array_push($aryHundreds, $zip2); } if($numberOfStatesToCompare==$counter){ $counter=0; $stringHundred=''; for ($i=0;$i<count($aryHundreds);$i++) { $stringHundred.=$aryHundreds[$i].'|'; } print 'markerHere:'.count($aryHundreds).'string'.$stringHundred; //unset($aryHundreds);// <--moving this to outside the if statement } unset($aryHundreds);// <--moved from above}?> Link to comment https://forums.phpfreaks.com/topic/27396-please-help-clear-array/#findComment-125357 Share on other sites More sharing options...
jonniejoejonson Posted November 16, 2006 Author Share Posted November 16, 2006 Thanks both for your responses. I have manipulated my script somewhat, and it still does not work using unset, however by resetting it using $aryHundreds = array();now works with my changed code. So that is brilliant. What isn't so good is that it still isn't as fast as I hoped!!!. However it will have to do. Thanks both for your help. Jonnie. Link to comment https://forums.phpfreaks.com/topic/27396-please-help-clear-array/#findComment-125366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.