匿名函数(闭包)

29 篇文章 0 订阅
9 篇文章 0 订阅

定义

匿名函数,也叫闭包函数,允许临时创建一个没有制定名称的函数。最经常用作回调函数(callback)参数的值

使用

闭包函数可以作为遍历的值来使用

代码实例

1.

public function index(){
        $message = 'guoyuzhao';
        $example = function () use (&$message){//如果使用外部变量用use,如果想闭包之后再赋值需要加上&
            echo $message;
        };
        $message = 'hahah';
        $example();
    }

2.你最关心的

<?php
namespace app\index\controller;
use Closure;//引入Closure
class Index
{
    public function index(){
        $this -> test('tuzi',function(){
            echo 'woshi tuzi';
        });
    }

    public function test($name,Closure $clo){
        echo "Hello,{$name}<br/>";
        $clo();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
It is important in distributed computer systems to identify those events (at identifiable points in time) that are concurrent, or not related to each other in time. A group of concurrent events may sometimes attempt to simultaneously use the same resource, and this could cause problems. Events that are not concurrent can be ordered in time. For example, if event 1 can be shown to always precede event 2 in time, then event 1 and 2 are obviously not concurrent. Notationally we indicate that event 1 precedes 2 by writing 1 ! 2. Note that the precedes relation is transitive, as expected. Thus if 1 ! 2 and 2 ! 3, then we can also note that 1 ! 3. Sequential events in a single computation are not concurrent. For example, if a particular computation performs the operations identified by events 1, 2 and 3 in that order, then clearly and 1 ! 2 and 2 ! 3. Computations in a distributed system communicate by sending messages. If event 1 corresponds to the sending of a message by one computation, and event 2 corresponds to the reception of that message by a different computation, then we can always note that 1 ! 2, since a message cannot be received before it is sent. In this problem you will be supplied with lists of sequential events for an arbitrary number of computations, and the identification of an arbitrary number of messages sent between these computations. Let n be the number of events. Your task is to write an O(n3) program to find out how many pairs of events are concurrent. Input The input will include first an integer, nc, specifying the number of computations in the test case. For each of these nc computations there will be a single line containing an integer ne that specifies the number of sequential events in the computation followed by ne event IDs. Following the specification of the events in the last computation there will be a line with a single integer, nm, that specifies the number of messages that are sent between computations. Finally, on each of the following nm lines there will be a pair of event IDs specifying the name of the event associated with the sending of a message, and the event associated with the reception of the message. These IDs will have previously appeared in the lists of events associated with computations. e.g.: 2 2 1 2 2 3 4 1 3 1 Output Your output should be the number of pairs of concurrent events. e.g., the output for the above input should be: 2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值