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

  • SEARCH
  • Home
  • 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

recently I came across this term,but really have no idea what it refers to.I've
We (our IT partner really) recently changed some DNS for a web farmed site
I saw a screencast recently and what really got me interested is that messages
I'm really new to programming, and creating programs. Recently I was browsing around iTunes
I recently asked a question on formatting a telephone number and I got lots
A little while back (after recently installing VStudio 2010) I used the Go to
Longtime Eclipse user here; I recently discovered the Block Selection Mode (Alt-Shift-A) that was
Bear with me... I don't think this is too subjective but maybe I'm wrong.
As I've been using Grails more and more, I find myself writing code in
My friend (who knows nothing about programming what-so-ever) asked me if I could develop

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.