FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » array_walk always passing 0 as the parameter
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
array_walk always passing 0 as the parameter [message #178200] Tue, 22 May 2012 13:13 Go to next message
Mike is currently offline  Mike
Messages: 18
Registered: December 2010
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
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' );


Thanks!

Mike
Re: array_walk always passing 0 as the parameter [message #178201 is a reply to message #178200] Tue, 22 May 2012 13:38 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
.oO(Mike)

> 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' );

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.

and

| 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.

Micha

--
http://mfesser.de/blickwinkel
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: array filtering question
Next Topic: is_dir true from cli, false from Apache
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Oct 23 13:18:10 EDT 2017

Total time taken to generate the page: 0.00660 seconds