Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:50:40+00:00 2026-05-13T18:50:40+00:00

I recently really wanted to us anonymous functions in PHP. Unfortunately my host is

  • 0

I recently really wanted to us anonymous functions in PHP. Unfortunately my host is still on 5.2. I automatically thought this would work:

uasort($array, function($a, $b) {
    return $a > $b;
});

Is this how they work? Simply passed in as an argument instead of a callback? The docs don’t say specifically that’s how they do, but I have a working knowledge of JavaScript’s anonymous functions, so I assumed they would.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:50:40+00:00Added an answer on May 13, 2026 at 6:50 pm

    Yes. You can use it in place of regular PHP callbacks.

    Try this (in PHP 5.3):

    function wait($callback)
    {
        sleep(10);
        call_user_func($callback);
    }
    
    wait(function(){
        echo "Hello!";
    });
    

    How call_user_func() works is it will accept any of the following:

    'functionName'
    array('className', 'methodName')
    array($objectInstance, 'methodName');
    

    and now in PHP 5.3

    function(){ // .. do something .. 
    }
    

    My guess is that internal PHP functions user call_user_func() for callbacks, and because it has support for anonymous functions, they will work just as well as other callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So recently I've really started to use php actively, and I need some insights
I'm using MongoDB and we are really happy with this DB. But recently our
I've recently done a migration from a really old version of some application to
I recently installed twython, a really sleek and awesome twitter API wrapper for Python.
Recently I've gotten sick and tired of writing release notes and I'm really starting
I recently looked into Prism (aka the Composite Application Library for WPF) and really
I began studying Java Regular Expression recently and I found some really intersting task.For
Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving
Recently I was trying some practice programs in python and I came across this
Recently I came across the SkipList data structure. It really helped me to solve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.