zoukankan      html  css  js  c++  java
  • php中call_user_func_array()的使用

     1 <?php
     2 
     3 function demo($num$n) {
     4     for ($i = 0; $i < $num$i++) {
     5         //if ($n($i))
     6         if (call_user_func_array($narray($i)))
     7             continue;
     8         echo $i.'<br>';
     9     }
    10 }
    11 
    12 class Filter
    13 {
    14     function one($i)
    15     {
    16         if ($i == strrev($i))
    17             return true;
    18         else 
    19             return false;
    20     }
    21 
    22     static function two($i)
    23     {
    24         if ($i%3 == 0)
    25             return true;
    26         else 
    27             return false;
    28     }
    29 }
    30 
    31 function test($i) {
    32     if ($i%3 == 0) 
    33         return true;
    34     else 
    35         return false;
    36 }
    37 
    38 //demo(500, 'test');
    39 
    40 //demo(500, array('new Filter()', 'one');
    41 //
    42 //demo(500, array(new Filter(), 'one'));
    43 //
    44 demo(500, array('Filter', 'two'));
     
    call_user_func(array($class, $method));
    // 其中如果$class传入的是一个实例化的对象,那么调用不是静态方法(static),传入的是字符串那么调用的是静态方法(static)
    I need you ideas!
  • 相关阅读:
    转C++的一点点
    无向图hash
    字符串相关
    Tutte矩阵求一般图最大匹配
    FFT的常数优化
    洲阁筛
    半平面交
    非旋treap套线段树
    点分治 [IOI2011]Race
    treap
  • 原文地址:https://www.cnblogs.com/xfjpeter/p/5686939.html
Copyright © 2011-2022 走看看