> 
> did you read the help for those functions on php.net?

Yes, I found a "recursive" way to find out the "index" like I wanted, by doing 
something like 

$from = explode("-", $from);
$state_colors= explode("-", $state_colors);
$change = explode("-",$change);

$count = count($new_array);
$i=0;
foreach ($new_array as $key => $value){
 echo $i . " " . $key . " is " . $value . " miles away<br />";
 $i++;
}

You can see it is not very elegant, and plus, I created the $new_array so I 
could do the ordering according to the values of the change array. I can tell 
that since this is not a single array, which is probably why array_search does 
not work. 
Since I don't need the "value" of my "new_array" here, I am still finding out 
how to "strip off" the values here without having to flatten my array. Is what 
I am trying to do here possible? Or, is there a trick in array_search that I 
could use to find the index without having to strip off anything?

Thanks for your help.

Alice

> 
> On Wed, Mar 10, 2010 at 4:12 PM, Alice Wei <aj...@alumni.iu.edu> wrote:
> >
> > Hi,
> >
> >  I have the code as shown in the following that I am trying to create the 
> > image of based on the file loaded into the file and additional edits. The 
> > problem here appears to be that no matter what value I have in the 
> > $distance_to_destination variable, it does not affect any changes on the 
> > map. What I am trying to do here is to create a map based on the pre-passed 
> > through colors of individual states from another program, but I have to 
> > match up the colors based on the values of the correct states.
> >
> >  I figured that I may have problems with
> >
> >    $key= array_search($location2,$from); //Find out the position of the 
> > index in the array
> >
> >    $colors_style = ";fill:" . $state_colors[$key];  //Use the index from 
> > array_search to apply to the color index
> >
> > Obviously, it is not applying the colors to the states that I would like 
> > other than doing it one by one as the order of what is in the $from 
> > variable. Could someone please give me some hints on how I could do the 
> > array_search here based on the "value" of the values in the 
> > $distance_to_distance and apply the color to the states?
> >
> > <?php
> >
> > header("Content-type: image/svg+xml"); //Outputting an SVG
> >
> > $from = $_GET['from'];
> > $state_colors= $_GET['state_colors'];
> > $distance_to_destination= $_GET['distance_to_destination'];
> >
> > $from = explode("-", $from);
> > $state_colors= explode("-", $state_colors);
> > $change = explode("-",$change);
> >
> > #Load the Map
> > $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
> > $fh = fopen($ourFileName, "r") or die("Can't open file");
> > $contents = fread($fh,filesize($ourFileName));
> > $lines2= file($ourFileName);
> >
> > foreach ($lines2 as $line_num => $line2) {
> >
> > $style_line_num = $line_num+3;
> > $line2 = trim($line2);
> >
> >      if(preg_match("/^style/",$line2)) {
> >
> >       $rest = substr($line2,0,-1);
> >
> >       for ($j=$line_num;$j<=$style_line_num;$j++){
> >         if(preg_match("/inkscape:label/",$lines2[$j])) {
> >            $location = explode("=",$lines2[$j]);
> >            $location2 = substr($location[1],1,-6);
> >
> >            if(in_array($location2, $from)) {
> >
> >             $key= array_search($location2,$from); //Find out the position 
> > of the index in the array
> >             $colors_style = ";fill:" . $state_colors[$key];  //Use the 
> > index from array_search to apply to the color index
> >             $rest2 = substr($line2,0,-1). $colors_style . "\"";
> >             echo $rest2 . "\n";
> >            }
> >            else echo $line2 . "\n";
> >
> >         } //end preg_match inkscape
> >     } //end for loop
> >   }  //If preg_match style
> >
> >     else echo $line2 . "\n"; //else if preg_match style
> >  } //end for each
> >
> > fclose($fh);
> > ?>
> >
> > Thanks for your help.
> >
> > Alice
> >
> > _________________________________________________________________
> > Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
> > http://clk.atdmt.com/GBL/go/201469226/direct/01/
                                          
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/

Reply via email to