usort and lambda functions used in php

what is the use of usort () and lambda function in php.? explain with examples


1 Answer
1-1 of  1
1 Answer
  • 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
    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
    $greeting=function()
    {
    return "hello";
    }

    echo $greeting();
    ?>

Php

Didn't get the answer.
Contact people of Talent-Php directly by clicking here