Re: [PHP] function to discover if value is already in array

2003-02-21 Thread Ray
On Friday 21 February 2003 09:08, you wrote:
 Here is an example array:


 array(
  array(1,2),
  array(2,3),
  array(3,1)
 )

 now suppose I get some form inputs with the value 1 and 1. I am trying to
 find a way to figure out if the first coloumn is already in the table and
 if so just add the second coloumn to the first. I have tried various
 combinations of foreaches, in_array and array_search.

 Has anyone had a similar problem and found a soloution?

would something like 
array(
  1 = 2,
  2 = 3,
  3 = 1
 )
work?
and use array_key_exists to see if the 1st 'colomn' has a value of one?

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




Re: [PHP] function to discover if value is already in array

2003-02-21 Thread 1LT John W. Holmes
 Here is an example array:


 array(
  array(1,2),
  array(2,3),
  array(3,1)
 )

 now suppose I get some form inputs with the value 1 and 1. I am trying to
 find a way to figure out if the first coloumn is already in the table and
 if so just add the second coloumn to the first. I have tried various
 combinations of foreaches, in_array and array_search.

 Has anyone had a similar problem and found a soloution?

If you can have:

$array = array(array('1','2','3'),array('2','3','1'));

You can use this:

$key = array_search($search_for,$array[0]);
if($key !== FALSE)
{ $array[1][$key] += $add_value; }

Otherwise, with the way you have your array now, you have to search
$array[0][0], $array[1][0], $array[2][0], etc, with a loop.

---John Holmes...


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