Re: [PHP] Re: If I have 2 arrays...

2005-06-17 Thread Jochem Maas

Jason Barnett wrote:

Jay Blanchard wrote:


[snip]
Close... I think array keys are preserved from the (original) first 
array, but other than that those appear to be the values that should 
intersect.

[/snip]

After a var_dump I am seeing that there is an extra space in each
element of one array, so no intersection occurs. 



Well then there you have it... having an extra space means that the 
strings in the first array won't match the strings in the second array. 
 Perhaps you can array_intersect(array_walk($array1, 'trim'), $array2)


you'd want array_map not array_walk in this case:

array_intersect(array_map($array1, 'trim'), $array2)



also I found myself writing the following 2 funcs because the std
functions provided don't do what I 'mean'. e.g.:

array_intersect_assoc
array_intersect_key
array_intersect_uassoc
array_intersect_ukey
array_intersect
...etc


/**
 * array_intersect_keys()
 *
 * returns the all the items in the 1st array whose keys
 * are found in any of the other arrays
 *
 * @return array()
 */
function array_intersect_keys()
{
$args   = func_get_args();
$originalArray  = $args[0];
$res= array();

if(!is_array($originalArray)) { return $res; }

for($i=1;$i $data) {
if (isset($originalArray[$key]) && !isset($res[$key])) {
$res[$key] = $originalArray[$key];
}
}
}

return $res;
}

/**
 * array_diff_keys()
 *
 * returns the all the items in the 1st array whose
 * keys are not found in any of the other arrays
 *
 * @return array()
 */
function array_diff_keys()
{
$args = func_get_args();
$res  = $args[0];

if(!is_array($res)) { return array(); }

for($i=1;$i $data) {
unset($res[$key]);
}
}

return $res;
}







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



Re: [PHP] Re: If I have 2 arrays...

2005-06-16 Thread Jason Barnett

Jay Blanchard wrote:

[snip]
Close... I think array keys are preserved from the (original) first 
array, but other than that those appear to be the values that should 
intersect.

[/snip]

After a var_dump I am seeing that there is an extra space in each
element of one array, so no intersection occurs. 


Well then there you have it... having an extra space means that the 
strings in the first array won't match the strings in the second array. 
 Perhaps you can array_intersect(array_walk($array1, 'trim'), $array2)


--
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php

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



RE: [PHP] Re: If I have 2 arrays...

2005-06-16 Thread Jay Blanchard
[snip]
Close... I think array keys are preserved from the (original) first 
array, but other than that those appear to be the values that should 
intersect.
[/snip]

You are correct, I was more worried about the values

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



RE: [PHP] Re: If I have 2 arrays...

2005-06-16 Thread Jay Blanchard
[snip]
Close... I think array keys are preserved from the (original) first 
array, but other than that those appear to be the values that should 
intersect.
[/snip]

After a var_dump I am seeing that there is an extra space in each
element of one array, so no intersection occurs. 

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



[PHP] Re: If I have 2 arrays...

2005-06-16 Thread Jason Barnett
Close... I think array keys are preserved from the (original) first 
array, but other than that those appear to be the values that should 
intersect.


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