[PHP] Array Search

2011-03-25 Thread Ethan Rosenberg

Dear List -

Here is a code snippet:

$bla = array(g1 = $results[7][6],
   h1  = $results[7][7]);
print_r($bla);
$value = h1;
   $locate1 = array_search($value, $bla);
   echo This is locate ; print_r($locate1);
   if(in_array($value, $bla)) print_r($bla);

Neither the array_search or the in_array functions give any results. 
I have tried it with both h1 and h1;


$results[7][6]  = Wn;
$results[7][7]  =  Wr;

This is a chess board  where g1 and h1 are the coordinates and the 
results array contains the pieces at that coordinate.


What am I doing wrong?

Advice and comments please.

Thanks.

Ethan Rosenberg 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array Search Problem

2010-03-11 Thread Alice Wei

Hi, 

  At the time when I am writing this, looks like I already got the functions I 
needed. It turned out that I had to use some array_combine, sorting the items 
by keys instead of values as well as using array_keys to get the values I 
needed. 

Thanks for pointing me towards the right direction. 

Alice


 From: rene7...@gmail.com
 Date: Thu, 11 Mar 2010 07:12:15 +0100
 Subject: Re: [PHP] Array Search Problem
 To: aj...@alumni.iu.edu
 CC: php-general@lists.php.net
 
 (almost) all the tricks are in the comments of the help page for a
 function, on php.net
 
 but all functions accept only a given (and usually documented) set of
 parameter(type)s, so you'll probably have to prepare the var, or even
 call the function in a loop, outputting to yet another descriptively
 named array that'll be used as wanted list later in the code.
 
 On Wed, Mar 10, 2010 at 6:57 PM, Alice Wei aj...@alumni.iu.edu wrote:
 
  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 awaybr /;
   $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

[PHP] Array Search Problem

2010-03-10 Thread Alice Wei

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/

[PHP] Array Search Not Working?

2010-03-10 Thread Alice Wei

Hi,

  I have two arrays here that I have combined into a new array, as shown here:

$from = explode(-, $from);
$change = explode(-,$change);
$new_array = array_combine($from,$change);

I then tried reading it from a file and do string matches, trying to find out 
the key using the array_search of the individual array elements. I seem to 
have no such luck, even when I copied one of the elements after I do a 
print_r($new_array); 

Here is the code,

foreach ($lines2 as $line_num = $line2) { 
$style_line_num = $line_num+3;

  if(preg_match(/^style/,$line2)) {
   
if(preg_match(/inkscape:label/,$lines2[$style_line_num])) {  
$location = explode(=,$lines2[$style_line_num]);
$location2 = substr($patient_location[1],1,-6);  
 
 if(in_array($location2, $from)) {  
 $key= array_search($location2,$new_array); //Find out the position 
of the index in the array
 echo Key  . $key . br;  //This only gives me a blank space 
after the word Key
 
} 

 } //end preg_match inkscape   
   }  //If preg_match style

I looked at the example from 
http://php.net/manual/en/function.array-search.php, and looks like what I am 
trying to do here is possible, and yet, why am I not getting a proper key 
return?

Thanks for your help.

Alice
  
_
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/

Re: [PHP] Array Search Problem

2010-03-10 Thread Rene Veerman
did you read the help for those functions on php.net?

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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array Search Problem

2010-03-10 Thread Alice Wei

 
 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 awaybr /;
 $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/

Re: [PHP] Array Search Problem

2010-03-10 Thread Rene Veerman
(almost) all the tricks are in the comments of the help page for a
function, on php.net

but all functions accept only a given (and usually documented) set of
parameter(type)s, so you'll probably have to prepare the var, or even
call the function in a loop, outputting to yet another descriptively
named array that'll be used as wanted list later in the code.

On Wed, Mar 10, 2010 at 6:57 PM, Alice Wei aj...@alumni.iu.edu wrote:

 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 awaybr /;
  $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. Get it now.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] array search

2005-01-23 Thread Malcolm

Hello All,
  I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this  -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
204.126.202.56=Mark,
63.230.76.166=Bob,
63.220.76.165=John,
);
function _array_search ($viz_ip, $byte_ip) {
   foreach($byte_ip as $key = $val) {
   if ($viz_ip === $key) {
   return($val);
   }
   }
   return(False);
   }
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm
--
O
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] array search

2005-01-23 Thread Jochem Maas
Malcolm wrote:

Hello All,
  I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this  -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
204.126.202.56=Mark,
63.230.76.166=Bob,
63.220.76.165=John,
);
function _array_search ($viz_ip, $byte_ip) {
   foreach($byte_ip as $key = $val) {
   if ($viz_ip === $key) {
   return($val);
   }
   }
   return(False);
   }
try:
function getValueInArr($val, $arr)
{
$val = (string)$val;
return is_array($arr)  isset($arr[$val]) ? $arr[$val]: false;
}
but maybe the $viz_ip really _isn't_ set in the array you have?
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] array search

2005-01-23 Thread john
 I've been trying for days now to make this work.

This worked for me (with my IP address for 'John'):

?php
$viz_ip= $_SERVER['REMOTE_ADDR'];
echo (Your IP is $viz_ip);

$byte_ip= array(

204.126.202.56=Mark,

63.230.76.166=Bob,

84.196.101.86=John,
);

function _array_search ($viz_ip, $byte_ip) {

foreach($byte_ip as $key = $val) {

if ($viz_ip === $key) {
return($val);
}

}

return(False);
}



?


pHi ?php echo (_array_search($viz_ip, $byte_ip)); ?/p

J

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array search

2005-01-23 Thread Malcolm
Thank you Sirs,
  I was echoing the viz-ip so I know it was getting set but
I couldn't get it.
  both work  ..  I got the clue from John, the last echo line did the  
trick.

On Sun, 23 Jan 2005 17:26:58 +0100, Jochem Maas [EMAIL PROTECTED]  
wrote:

Malcolm wrote:
  Hello All,
   I've been trying for days now to make this work.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] array search

2005-01-23 Thread Ben Edwards
probably missing something but php have a function called array_search.

Ben

On Sun, 23 Jan 2005 11:33:16 -0500 (EST), [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
  I've been trying for days now to make this work.
 
 This worked for me (with my IP address for 'John'):
 
 ?php
 $viz_ip= $_SERVER['REMOTE_ADDR'];
 echo (Your IP is $viz_ip);
 
 $byte_ip= array(
 
 204.126.202.56=Mark,
 
 63.230.76.166=Bob,
 
 84.196.101.86=John,
 );
 
 function _array_search ($viz_ip, $byte_ip) {
 
 foreach($byte_ip as $key = $val) {
 
 if ($viz_ip === $key) {
 return($val);
 }
 
 }
 
 return(False);
 }
 
 
 ?
 
 pHi ?php echo (_array_search($viz_ip, $byte_ip)); ?/p
 
 J
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
Ben Edwards - Poole, UK, England
WARNING:This email contained partisan views - dont ever accuse me of
using the veneer of objectivity
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles.php?uid=4
(email address this email is sent from may be defunct)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] array search in 2-D arrays

2002-05-15 Thread Pushkar Pradhan

I've a 2 D array and would like to search for vals. in the first dimension
only i.e.
myArray[0][0]
myArray[1][0]
myArray[2][0]
myArray[3][0]
.
.
.
and not in the elements myArray[0][1]

CODE:
for($l = 0; $l  count($layer); $l++) {
   $key = array_search($layer[$l], $layerDes);   // $layerDes is 2-D
   $layer[$l] = $layerNames[$key];
}
My $key is FALSE/0 after execution, is it because the elements are in
$layerDes[i][0]?
Using $key === also didn't help? Any ideas, thanks.


-Pushkar S. Pradhan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] array search in 2-D arrays

2002-05-15 Thread Pushkar Pradhan

Oops! Sorry I got a reply for this but didn't read my mail carefully
enough. Thanks to Tim Ward for pointing out the problem.
 I've a 2 D array and would like to search for vals. in the first dimension
 only i.e.
 myArray[0][0]
 myArray[1][0]
 myArray[2][0]
 myArray[3][0]
 .
 .
 .
 and not in the elements myArray[0][1]

 CODE:
 for($l = 0; $l  count($layer); $l++) {
$key = array_search($layer[$l], $layerDes);   // $layerDes is 2-D
$layer[$l] = $layerNames[$key];
 }
 My $key is FALSE/0 after execution, is it because the elements are in
 $layerDes[i][0]?
 Using $key === also didn't help? Any ideas, thanks.


 -Pushkar S. Pradhan


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-Pushkar S. Pradhan



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] array search

2001-08-31 Thread Joseph Bannon

I have an array of names, like below...

$people = array(Jim,John,JP);

Is there a way in an IF statement to see if someone's name is in the array?
Like...

if ($people =~ $person) { }

I don't want to have to create a foreach loop to go through the array to see
if that person is there.

Joseph



















-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array search

2001-08-31 Thread Andrey Hristov

from http://php.net/quickref.php

$os = array (Mac, NT, Irix, Linux);
if (in_array (Irix, $os)){
print Got Irix;
}
  
Andrey HristovIcyGEN Corporationhttp://www.icygen.comBALANCED SOLUTIONS
- Original Message - 
From: Joseph Bannon [EMAIL PROTECTED]
To: PHP (E-mail) [EMAIL PROTECTED]
Sent: Friday, August 31, 2001 6:40 PM
Subject: [PHP] array search


 I have an array of names, like below...
 
 $people = array(Jim,John,JP);
 
 Is there a way in an IF statement to see if someone's name is in the array?
 Like...
 
 if ($people =~ $person) { }
 
 I don't want to have to create a foreach loop to go through the array to see
 if that person is there.
 
 Joseph
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array search

2001-08-31 Thread Philip Olson

just to add some info.  rememember this is case sensitive and spaces do
matter, sometimes (depending on your goals) the following will apply :

  $good_names = array('jim','philip','sasheen');

  $my_name= 'PHiliP';

  if (in_array(trim(strtolower($my_name)),$good_names))

and, another good function is array_keys and array_search.  see :

  http://www.php.net/array

regards,
Philip Olson

On Fri, 31 Aug 2001, Andrey Hristov wrote:

 from http://php.net/quickref.php
 
 $os = array (Mac, NT, Irix, Linux);
 if (in_array (Irix, $os)){
 print Got Irix;
 }
   
 Andrey HristovIcyGEN Corporationhttp://www.icygen.comBALANCED SOLUTIONS
 - Original Message - 
 From: Joseph Bannon [EMAIL PROTECTED]
 To: PHP (E-mail) [EMAIL PROTECTED]
 Sent: Friday, August 31, 2001 6:40 PM
 Subject: [PHP] array search
 
 
  I have an array of names, like below...
  
  $people = array(Jim,John,JP);
  
  Is there a way in an IF statement to see if someone's name is in the array?
  Like...
  
  if ($people =~ $person) { }
  
  I don't want to have to create a foreach loop to go through the array to see
  if that person is there.
  
  Joseph
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
  
  
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] array search

2001-08-31 Thread Alfredeen, Johan

Joseph,
 The below postings are what you're looking for. Hopefully the in_array PHP
function uses a smart search algorithm and doesn't go through the entire
array. If you store your values in a db you can make use of an index on the
column, or you could write your own search algorithm that uses a btree or
some other type of search methodology.

Johan


-Original Message-
From: Papp Gyozo [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 31, 2001 10:02 AM
To: Joseph Bannon; PHP (E-mail)
Subject: Re: [PHP] array search


yes, in_array($person, $people)!

however, you may take a look into the manual.
- Original Message -
From: Joseph Bannon [EMAIL PROTECTED]
To: PHP (E-mail) [EMAIL PROTECTED]
Sent: Friday, August 31, 2001 5:40 PM
Subject: [PHP] array search


 I have an array of names, like below...

 $people = array(Jim,John,JP);

 Is there a way in an IF statement to see if someone's name is in the
array?
 Like...

 if ($people =~ $person) { }

 I don't want to have to create a foreach loop to go through the array to
see
 if that person is there.

 Joseph



















 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] array search

2001-08-31 Thread Joseph Bannon

What about going the other way? Say I have a sentence...

Hi, my name is Bob.

...and I want to search the sentence for one of the values (people) in the
array...

$people = array(Jim,John,JP,Bob);

Can this be done?


Thanks,
Joseph




-Original Message-

yes, in_array($person, $people)!

however, you may take a look into the manual.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] array search

2001-08-31 Thread Philip Olson

try this :

  $people  = array ('philip','sasheen','jim');
  $string  = 'Hi, my name is philip, I miss Sasheen';

  foreach ($people as $person) {
 
if (stristr($string,$person)) {
  $matches[] = $person;
}
  }
 
  // results live in $matches now.

  print_r($matches);

stristr is case insensitive, strstr is case sensitive.  modify to suit
your needs.

regards,
Philip Olson


On Fri, 31 Aug 2001, Joseph Bannon wrote:

 What about going the other way? Say I have a sentence...
 
 Hi, my name is Bob.
 
 ...and I want to search the sentence for one of the values (people) in the
 array...
 
 $people = array(Jim,John,JP,Bob);
 
 Can this be done?
 
 
 Thanks,
 Joseph
 
 
 
 
 -Original Message-
 
 yes, in_array($person, $people)!
 
 however, you may take a look into the manual.
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] array search

2001-08-31 Thread Philip Olson

btw, you may want to search for a name surrounded by spaces as philip vs
philips, jim vs jimmy, etc.  probably other considerations as well, or
maybe not :)

philip


On Fri, 31 Aug 2001, Philip Olson wrote:

 try this :
 
   $people  = array ('philip','sasheen','jim');
   $string  = 'Hi, my name is philip, I miss Sasheen';
 
   foreach ($people as $person) {
  
 if (stristr($string,$person)) {
   $matches[] = $person;
 }
   }
  
   // results live in $matches now.
 
   print_r($matches);
 
 stristr is case insensitive, strstr is case sensitive.  modify to suit
 your needs.
 
 regards,
 Philip Olson
 
 
 On Fri, 31 Aug 2001, Joseph Bannon wrote:
 
  What about going the other way? Say I have a sentence...
  
  Hi, my name is Bob.
  
  ...and I want to search the sentence for one of the values (people) in the
  array...
  
  $people = array(Jim,John,JP,Bob);
  
  Can this be done?
  
  
  Thanks,
  Joseph
  
  
  
  
  -Original Message-
  
  yes, in_array($person, $people)!
  
  however, you may take a look into the manual.
  
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
  
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array search

2001-08-31 Thread Martín Marqués

On Vie 31 Ago 2001 17:49, you wrote:
 What about going the other way? Say I have a sentence...

 Hi, my name is Bob.

 ...and I want to search the sentence for one of the values (people) in the
 array...

 $people = array(Jim,John,JP,Bob);

 Can this be done?

Yes, split the sentence into parts of the array (use split or explode), then 
all you have to do is walk through $people with foreach askink if that word 
is in, for example $word that is the array that you got after the split (or 
explode).

Saludos, :-)

-- 
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-
Martín Marqués  |[EMAIL PROTECTED]
Programador, Administrador, DBA |   Centro de Telematica
   Universidad Nacional
del Litoral
-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array search

2001-08-31 Thread Papp Gyozo

yes, in_array($person, $people)!

however, you may take a look into the manual.
- Original Message -
From: Joseph Bannon [EMAIL PROTECTED]
To: PHP (E-mail) [EMAIL PROTECTED]
Sent: Friday, August 31, 2001 5:40 PM
Subject: [PHP] array search


 I have an array of names, like below...

 $people = array(Jim,John,JP);

 Is there a way in an IF statement to see if someone's name is in the
array?
 Like...

 if ($people =~ $person) { }

 I don't want to have to create a foreach loop to go through the array to
see
 if that person is there.

 Joseph



















 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]