Swift - 函数参数中的闭包

时间:2015-07-25 04:33:27

标签: ios swift

我是iOS和swift的新手,试图了解基础知识。我在操场上尝试了以下两个函数调用,我希望结果相同,但第一个返回一个值,第二个返回两个值。

你能解释一下为什么吗?

<?php
if(isset($_POST['sub'])){
    $db_host="localhost";
    $db_username="root";
    $db_password="";
    $db_name="14";
    $con=mysql_connect("$db_host", "$db_username", "$db_password") or die("could not connect to mysql!!!");
    if($con=="")
    {
        echo "Database not connected!!!!";
    }
    else
    {
        $isdb=mysql_select_db("$db_name") or die("database not available!!!!");
        if($isdb=="")
        {
            echo "database not selected!!!!";
        }
        else
        {   
            $emp_ID=$_POST['emp_ID'];
            $code=$_POST['code'];

            $query = mysql_query("select * from oc_abhireward where `Code`='$code'") or die (mysql_error());
            $data=mysql_fetch_assoc($query);
            $code_db=$data['Code'];
            $points_db=$data['Point'];
            if($code==$code_db)
            {
            $query1 = mysql_query("select * from oc_customer where `emp_ID`='$emp_ID'") or die (mysql_error());
            $data1=mysql_fetch_assoc($query1);
            $customer_id=$data1['customer_id'];
            $query2=mysql_query("INSERT INTO `oc_customer_reward` (customer_id, order_id, description, Code, points, date_added) VALUES ($customer_id, 0, 'rewarded',  '$code', $points_db, NOW());");
            $query4=mysql_query("INSERT INTO `oc_customer_recharge`(emp_ID, Code, points, date_added) VALUES ('$emp_ID', '$code', $points_db, NOW());");
                    if ($code==$code_db)
                    {
                    query5 = mysql_query("select * from oc_customer_recharge where Code='$code'")or die (mysql_error());
                    $data2=mysql_fetch_assoc($query4);
                    $emp_ID=$data2['emp_ID'];
                    $query6 = mysql_query("DELETE FROM oc_abhireward WHERE Code='$code'");
                    }
                    else
                    {
                    exit();
                    }

            header("location:http://localhost/14/index.php?route=account/account");
            exit();
            }
            else
            {

            }           
        }
    }
}
?>

不应该用关闭返回6.5的函数调用吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

但结果是一样的。您可以尝试将其分配给var

var result = avgOfSqrts(2, 3, {x in return x * x})
result //this is 6.5 as expected