Results 1 to 2 of 2

Thread: usort and lambda functions used in php

  1. #1
    Join Date
    Jul 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default usort and lambda functions used in php

    Hello All, Can anyone help me out usort and lambda functions used in php. And where I can improve our PHP skills?

  2. #2
    Join Date
    Jul 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    usort is used in php4,php5,php6.
    It is used for sorting array which is defined by user.

    syntax:: usort(array,function_name)

    for example::

    PHP Code:
    <?php
    function sort($i,$j)
    {
    if(
    $i==$j)
    return 
    0;
    else
    return (
    $i>$j?-1:1;
    }
    $i=array(1,2,3,4,5,6,7,8,9)
    usort($i,"sort");

    ?>

    Lambda is an anonymous function .It is used with array_map(), array_filter(), array_reduce functions of php.

    For example::

    PHP Code:
    <?php
    $greeting
    =function()
    {
    return 
    "hello";
    }

    echo 
    $greeting();
    ?>
    Last edited by keyboard; 07-26-2019 at 01:46 AM. Reason: removed spam

Similar Threads

  1. USORT on timestamps
    By valkyriesound in forum PHP
    Replies: 6
    Last Post: 08-23-2011, 04:13 PM
  2. Resolved where should functions be placed?
    By james438 in forum PHP
    Replies: 10
    Last Post: 06-10-2011, 08:35 PM
  3. php functions
    By awakener1986 in forum PHP
    Replies: 2
    Last Post: 02-03-2010, 03:36 PM
  4. PHP Functions
    By twQ in forum PHP
    Replies: 3
    Last Post: 01-25-2010, 02:34 PM
  5. Calling Functions from Functions.
    By clowes in forum JavaScript
    Replies: 32
    Last Post: 12-21-2009, 05:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •