array_walk always passing 0 as the parameter

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
array_walk is passing (int)0 as the parameter every time.  What am I doing wrong?

I have a method to clean data, FilterInput::clean($value,$type), which I'm
calling.  I need to pass it the variable and the type I expect it to be.

When array_walk calls the function, I pass the variable type ('string' or 'int')
to the method, but when it get's there the parameter always =0.

My code:

$data = array();
$data[0] = array('A Value','Another Value','Different Value');
$data[1] = array('12345','54321','11223');

array_walk( $data[0], array('FilterInput','clean'), 'string' );
array_walk( $data[1], array('FilterInput','clean'), 'int' );



Re: array_walk always passing 0 as the parameter


Quoted text here. Click to load it

The callback function should accept three parameters. From the manual:

| Typically, funcname takes on two parameters. The array parameter's
| value being the first, and the key/index second.


| If the optional userdata parameter is supplied, it will be passed as
| the third parameter to the callback funcname.

Also note:

| If funcname needs to be working with the actual values of the array,
| specify the first parameter of funcname as a reference. Then, any
| changes made to those elements will be made in the original array
| itself.



Site Timeline