• Wicked!

    I had no idea you could use lambdas recursively.

  • They do, but don’t forget the “use” and the & sign:

  • alex barbu

    PHP still has to learn from javascript when it dealing with functions.
    These lambdas and other revolutionary additions to 5.3 are not enough to make me pay for the new ZCE exam.
    Looks like they’re out of funds…

  • Boby

    It’s a nice piece of code, but still not working deeper. Try the following array and you should have the key “foo” removed, but it isn’t. At least for me now with PHP 5.3.3

    Also, it should remove “bikes” as it’s an empty array.

    PS: seems like your comment form stops working when I post code. Just add to the “cars” array a few more arrays, and one element of it should be empty.

    Boby

  • Thank You! That function short and sweet.

  • Thomas

    I used this for unsetting specific values from an array.

  • Eugen Mihailescu

    A real working recursive implementation that goes as deep as possible, which is memory-friendly and CPU-friendly (read this) , is the one below:

    It does not involve the lambda function thus it should work with all PHP versions.
    I hope it helps.

  • Tudor

    This was more an example on lambdas. Also, in your example, I think you misspelled the name of the function, shouldn’t it be filter_me()?

Advertisment ad adsense adlogger