deko <ww************ *************** ****@nospam.com > wrote:
What I would do is this: Pass both arrays to array_map(), with null as the
callback function. You will end up with an array with the following
structure:
Array
(
[0] => Array
(
[0] => 3/4/04|20.123.112.2 1|grebos|http://www.asc.com
[1] => 2345
)
[1] => Array
(
[0] => 6/5/04|183.40.99.14 |boris|http://www.asc.com
[1] => 5466
)
)
So, this is a multi-dimensional array, correct?
Correct.
Write a function that decides whether an element should be removed. It'll
need to get the IP address via a global variable because array_filter()
doesn't let you pass data to the callback. Or if you want to be more
elegant, define a lamda function with create_function () that looks for
that specific IP. Anyway, the function would look something like this:
function NotMatchIP($a) {
global $ip;
$data_line = $a[0];
$data = explode("|", $data_line);
return ($ip != $data[1]);
}
is this a lamda function? What is a lamda function?
No. As soon as you use the control word "function" you have a named
function (here: NotMatchIP). A lambda function is an unnamed function,
created by create_function () and *only* by create_function ().
While you can call a named function using it's name (here:
MotMatchIp($foo )), you can't call a lambda function the same way, since it
has no name. Instead, you have a variable containing the function, calling
the variable with your parameters:
-----BEGIN PHP CODE BLOCK-----
$my_unnamed_fun ction = create_function ('$x','echo $x+1;');
$my_unnamed_fun ction(5); // outputs 6. notice the preceding dollar sign
$echo_next_inte ger = $my_unnamed_fun ction;
$echo_next_inte ger(17); // outputs 18.
------END PHP CODE BLOCK------
I am not sure about this, but I guess, that internally the concept of PHPs
"function pointers" is used, like in:
-----BEGIN PHP CODE BLOCK-----
$trigonomical_f unction = 'sin'; // string!
echo $trigonomical_f unction($x); // calls sin($x)
------END PHP CODE BLOCK------
Therefore echo $my_unnamed_fun ction should give you the internally used
name of the function. (Which is of no use, since it might change from one
parsing of the script to the next... It's just a technical detail.)
As you can see, you can "copy" the function to another variable, so you
could create whole bunches of functions, saving them in an array and
applying them one after another. All you have to do is to define a API of
parameters which will be used and returned:
-----BEGIN PHP CODE BLOCK-----
// define a function
function square($x) {
return $x*$x;
}
// list functions to use
$funcs = array(
'sin', // internal function
'square', // user-defined function
create_function ('$x','return $x*2') // lambda function
);
// output results
foreach ($funcs as $funcname)
echo $funcname . '(10) is: ' . $funcname(10) . chr(13);
------END PHP CODE BLOCK------
(Note: Every of these functions takes exactly one number.)
HTH
Simon
--
Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle