Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • array_map function php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 119
    Comment on it

    Welcome to Findnerd. Today we are going to discuss the array function that is array_map which takes two main arguments one for callback function and other arguments are in form of arrays. It will return the array according to callback function. array_map function passes the arrays to the callback function. Please have a look.

    <?php
    $pra = array(243,244,225,146);
    function productOpt($pra_num){
    return ($pra_num*$pra_num);
    }
    $final_arr = array_map("productOpt",$pra);
    ?>
    

    It will return the array according to callback function operation. array_map can also take multiple arrays. Please have a look.

    <?php
    $arr1 = array(243,244,225,146);
    $arr2 = array(143,444,525,143);
    function CompareOpt($arr1,$arr2){
    if($arr1>$arr2)
    return ($arr1);
    else
    return ($arr2);
    }
    $final_arr = array_map("CompareOpt",$arr1,$arr2);
    ?>
    

    In above example we created two different arrays and comparing the elements from both arrays.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: