• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP map函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中map函数的典型用法代码示例。如果您正苦于以下问题:PHP map函数的具体用法?PHP map怎么用?PHP map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了map函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: chain

/**
 * Applies a function to items of the array and concatenates the results.
 * This is also known as `flatMap` in some libraries.
 * ```php
 * $words = chain(split(' '));
 * $words(['Hello World', 'How are you']) // ['Hello', 'World', 'How', 'are', 'you']
 * ```
 *
 * @signature (a -> [b]) -> [a] -> [b]
 * @param  callable $fn
 * @param  array $list
 * @return array
 */
function chain()
{
    $chain = function ($fn, $list) {
        return concatAll(map($fn, $list));
    };
    return apply(curry($chain), func_get_args());
}
开发者ID:tarsana,项目名称:functional,代码行数:20,代码来源:list.php


示例2: memoize

/**
 * Memoizes callbacks and returns there value instead of calling them
 *
 * @param callable $callback Callable closure or function
 * @param array $arguments Arguments
 * @param array|string $key Optional memoize key to override the auto calculated hash
 * @return mixed
 */
function memoize($callback, array $arguments = array(), $key = null)
{
    Exceptions\InvalidArgumentException::assertCallback($callback, __FUNCTION__, 1);
    static $keyGenerator = null, $storage = array();
    if (!$keyGenerator) {
        $keyGenerator = function ($value) use(&$keyGenerator) {
            $type = gettype($value);
            if ($type === 'array') {
                $key = join(':', map($value, $keyGenerator));
            } elseif ($type === 'object') {
                $key = get_class($value) . ':' . spl_object_hash($value);
            } else {
                $key = (string) $value;
            }
            return $key;
        };
    }
    if ($key === null) {
        $key = $keyGenerator(array_merge(array($callback), $arguments));
    } else {
        $key = $keyGenerator($key);
    }
    if (!isset($storage[$key]) && !array_key_exists($key, $storage)) {
        $storage[$key] = call_user_func_array($callback, $arguments);
    }
    return $storage[$key];
}
开发者ID:reeze,项目名称:functional-php,代码行数:35,代码来源:Memoize.php


示例3: grid

 /**
  * Generates a table with a header column and a value column from the given array.
  *
  * @param mixed  $value
  * @param string $title        [optional]
  * @param int    $maxDepth     [optional] Max. recursion depth.
  * @param array  $excludeProps [optional] Exclude properties whose name is on the list.
  * @param bool   $excludeEmpty [optional] Exclude empty properties.
  * @param int    $depth        [optional] For internal use.
  * @return string
  */
 public static function grid($value, $title = '', $maxDepth = 1, $excludeProps = [], $excludeEmpty = false, $depth = 0)
 {
     if (is_null($value) || is_scalar($value)) {
         return self::toString($value);
     }
     if ($depth >= $maxDepth) {
         return "<i>(...)</i>";
     }
     if (is_object($value)) {
         if (method_exists($value, '__debugInfo')) {
             $value = $value->__debugInfo();
         } else {
             $value = get_object_vars($value);
         }
     }
     if ($title) {
         $title = "<p><b>{$title}</b></p>";
     }
     // Exclude some properties ($excludeProps) from $value.
     $value = array_diff_key($value, array_fill_keys($excludeProps, false));
     if ($excludeEmpty) {
         $value = array_prune_empty($value);
     }
     return $value ? "{$title}<table class=__console-table><colgroup><col width=160><col width=100%></colgroup>\n" . implode('', map($value, function ($v, $k) use($depth, $maxDepth, $excludeProps, $excludeEmpty) {
         $v = self::grid($v, '', $maxDepth, $excludeProps, $excludeEmpty, $depth + 1);
         return "<tr><th>{$k}<td>{$v}";
     })) . "\n</table>" : '<i>[]</i>';
 }
开发者ID:impactwave,项目名称:php-web-console,代码行数:39,代码来源:Debug.php


示例4: map

function map($nav, $item = 0, $object)
{
    if (!empty($nav[$item])) {
        ?>
<ul>
<?php 
        foreach ($nav[$item] as $key => $value) {
            ?>
  <li>
    <a href="<?php 
            echo $object->url(explode('/', $value['location']));
            ?>
">
      <?php 
            echo $value['name'];
            ?>
    </a>
<?php 
            map($nav, $key, $object);
            ?>
  </li>
<?php 
        }
        ?>
</ul>
<?php 
    }
}
开发者ID:cheevauva,项目名称:trash,代码行数:28,代码来源:FrontendIndex.php


示例5: solution

function solution($list)
{
    $acc = 1;
    $func = function ($item, $acc) {
        return $acc * $item;
    };
    $cellItAll = map($list, function ($item) {
        //map
        return ceil($item);
    });
    $leaveJustEven = filter($cellItAll, function ($item) {
        //filter
        return $item % 2 == 0;
    });
    $multiplyKill = accumulate($leaveJustEven, $func, $acc);
    //reduce
    ######################################################		// one line solution
    // return accumulate(filter(map($list, function($item) {
    // 	return ceil($item);
    // }), function($item) {
    // 	return $item % 2 == 0;
    // }), function($item, $acc) {
    // 	return $acc * $item;
    // }, $acc);
    return $multiplyKill;
}
开发者ID:4johndoe,项目名称:hexlet,代码行数:26,代码来源:reduce.php


示例6: rop_findexec

function rop_findexec()
{
    $x = [];
    $p = ptr() + 0;
    for ($i = 0; $i < 0x2000; $i++) {
        array_push($x, [0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141, 0x41414141]);
    }
    $a = map($p, 0x10000)[0];
    nogc($a);
    $a = bin2hex($a);
    nogc($a);
    $r = strpos($a, "3100000000000000100000000f0000000c000000010000000c00000000000000");
    if ($r !== FALSE) {
        $a = substr($a, $r + 0x80, 0x10);
        $a = hexdec(swapEndianness($a));
        $a = $a + 0;
        for ($i = 0; $i < 0x100000; $i++) {
            $k = map(($a & ~0xff) - 0x100 * $i, 0x8);
            if ("cffaedfe07000001" == bin2hex($k[0])) {
                return ($a & ~0xff) - 0x100 * $i + 0;
            }
        }
    }
    return FALSE;
}
开发者ID:kjungi704,项目名称:phpmess,代码行数:25,代码来源:pm_rop_findexec_osx.php


示例7: map

function map($fn, $list, $new_list = array())
{
    if (!car($list)) {
        return $new_list;
    }
    $new_list[] = $fn(car($list));
    return map($fn, cdr($list), $new_list);
}
开发者ID:emkay,项目名称:php-phant,代码行数:8,代码来源:phpphant.php


示例8: test_map

function test_map()
{
    $a = function ($x) {
        return $x * $x;
    };
    $range = range(0, 10);
    return is_identical(map($a, $range), array_map($a, $range));
}
开发者ID:Burgestrand,项目名称:Funcy,代码行数:8,代码来源:funcy.php


示例9: testMap

 public function testMap()
 {
     $expectedArr = array(2, 4, 6);
     $result = map(array(1, 2, 3), function ($item) {
         return $item * 2;
     });
     $this->assertEquals($result, $expectedArr);
 }
开发者ID:kiasaki,项目名称:vexillum,代码行数:8,代码来源:FunctionsTest.php


示例10: testMap

 public function testMap()
 {
     $range = range(0, 5);
     $mapped = map(function ($n) {
         return $n * 3;
     }, $range);
     $this->assertSame([0, 3, 6, 9, 12, 15], toArray($mapped));
 }
开发者ID:rexfordkelly-on-JS,项目名称:iter,代码行数:8,代码来源:iterTest.php


示例11: shouldCancelInputArrayPromises

 /** @test */
 public function shouldCancelInputArrayPromises()
 {
     $mock1 = $this->getMockBuilder('React\\Promise\\CancellablePromiseInterface')->getMock();
     $mock1->expects($this->once())->method('cancel');
     $mock2 = $this->getMockBuilder('React\\Promise\\CancellablePromiseInterface')->getMock();
     $mock2->expects($this->once())->method('cancel');
     map([$mock1, $mock2], $this->mapper())->cancel();
 }
开发者ID:reactphp,项目名称:promise,代码行数:9,代码来源:FunctionMapTest.php


示例12: map

/**
 * Returns a list resulting in invoking a function with each element of a list.
 *
 * @param callable $proc a function to invoke
 * @param Cons     $alist a list
 */
function map($proc, $alist)
{
    if (isNull($alist)) {
        return nil();
    } elseif (isPair($alist)) {
        return cons($proc(car($alist)), map($proc, cdr($alist)));
    } else {
        throw new \InvalidArgumentException("{$alist} is not a proper list");
    }
}
开发者ID:mudge,项目名称:php-microkanren,代码行数:16,代码来源:Lisp.php


示例13: __debugInfo

 function __debugInfo()
 {
     $linkToUrl = function (NavigationLinkInterface $link) {
         return $link->rawUrl();
     };
     return ['Current link' => $this->currentLink(), 'All IDs<sup>*</sup>' => PA($this->IDs)->keys()->sort()->join(', ')->S, 'All URLs<sup>*</sup><br>' . '<i>(in scanning order)</i>' => map($this->rootLink->getDescendants(), function (NavigationLinkInterface $link, &$i) {
         $i = $link->rawUrl();
         return $link->url();
     }), 'Trail<sup>*</sup>' => map($this->getCurrentTrail(), $linkToUrl), 'Visible trail<sup>*</sup>' => map($this->getVisibleTrail(), $linkToUrl), 'Navigation map<sup>*</sup>' => iterator_to_array($this->rootLink), 'request' => $this->request()];
 }
开发者ID:electro-framework,项目名称:framework,代码行数:10,代码来源:Navigation.php


示例14: test_basic

 function test_basic()
 {
     $function = function ($value) {
         return $value * 2;
     };
     $input = [1, 2, 3];
     $expect = [2, 4, 6];
     $map = map($function);
     $actual = iterator_to_array($map($input));
     $this->assertEquals($expect, $actual);
 }
开发者ID:morrisonlevi,项目名称:algorithm,代码行数:11,代码来源:MapTest.php


示例15: getAll

 function getAll()
 {
     $names = $this->getPropertyNames();
     // We must expose the 'macro' property on this method only, so that that macros can be correctly unserialized
     $names[] = 'macro';
     $x = map($names, function ($v, &$k) {
         $k = $v;
         return $this->{$k};
     });
     return $x;
 }
开发者ID:electro-modules,项目名称:matisse,代码行数:11,代码来源:MacroCallProperties.php


示例16: run

function run($times, $length)
{
    $a = new Benchmark('Functional Map x' . $times);
    $a1 = new Benchmark('Functional Map(w\\o plus) my_map x' . $times);
    $a2 = new Benchmark('Functional Map(w\\o plus) array_map x' . $times);
    $b = new Benchmark('array_map x' . $times);
    $c = new Benchmark('nromal map x' . $times);
    $manager = new Manager();
    $manager->addBenchmarks([$a, $a1, $a2, $b, $c]);
    $data = [];
    for ($i = 0; $i < $length; $i++) {
        $data[] = $i * 2 + 1;
    }
    $a->start();
    $plus = plus(1);
    for ($i = 0; $i < $times; $i++) {
        $res = map($plus, $data);
    }
    $a->stop();
    $a1->start();
    for ($i = 0; $i < $times; $i++) {
        $res = map2(function ($x) {
            return $x + 1;
        }, $data);
    }
    $a1->stop();
    $a2->start();
    for ($i = 0; $i < $times; $i++) {
        $res = map(function ($x) {
            return $x + 1;
        }, $data);
    }
    $a2->stop();
    $b->start();
    $func = function ($x) {
        return $x + 1;
    };
    for ($i = 0; $i < $times; $i++) {
        $res = array_map($func, $data);
    }
    $b->stop();
    $c->start();
    $func = function ($x) {
        return $x + 1;
    };
    for ($i = 0; $i < $times; $i++) {
        $res = [];
        foreach ($data as $i) {
            $res[] = $func($i);
        }
    }
    $c->stop();
    echo $manager->getResults('Test Array len =' . $length);
}
开发者ID:metaxy,项目名称:php-functional,代码行数:54,代码来源:map.php


示例17: get_mitglied

function get_mitglied($id)
{
    $arr = '';
    $query = "SELECT *,IF (DATE_FORMAT( CURDATE( ), '%m%d' ) >= DATE_FORMAT( geburtstag , '%m%d' ) , DATE_FORMAT( CURDATE( ) , '%Y' ) - DATE_FORMAT(geburtstag, '%Y' ) , DATE_FORMAT( CURDATE( ) , '%Y' ) - DATE_FORMAT( geburtstag, '%Y' ) -1) AS alter_jahre FROM mitglieder LEFT JOIN status ON (status.id=mitglieder.status) LEFT JOIN beitraghv ON (beitraghv.id=mitglieder.beitraghv) LEFT JOIN beitragst ON (beitragst.id=mitglieder.beitragst) LEFT JOIN beitragt ON (beitragt.id=mitglieder.beitragt) WHERE mid = {$id}";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    while ($line = mysql_fetch_assoc($result)) {
        foreach ($line as $key => $col_value) {
            if (map("mitglieder", $key)) {
                $arr[map("mitglieder", $key)] = utf8_encode($col_value);
            }
        }
    }
    return $arr;
}
开发者ID:rellla,项目名称:djkservice,代码行数:14,代码来源:inc.mitglieder.php


示例18: __call

 function __call($name, $args)
 {
     $method = "filter_{$name}";
     if (isset($this->filters[$method])) {
         return call_user_func_array($this->filters[$method], $args);
     }
     if (isset($this->fallbackHandler)) {
         if (method_exists($this->fallbackHandler, $method)) {
             return call_user_func_array([$this->fallbackHandler, $method], $args);
         }
     }
     throw new FilterHandlerNotFoundException(sprintf("<p><p>Handler method: <kbd>%s</kbd><p>Arguments: <kbd>%s</kbd>", $method, print_r(map($args, function ($e) {
         return Debug::typeInfoOf($e);
     }), true)));
 }
开发者ID:electro-modules,项目名称:matisse,代码行数:15,代码来源:FilterHandler.php


示例19: getQueries

 function getQueries()
 {
     $this->mute();
     $queries = map($this->db->connection()->pretend(function () {
         $this->run();
     }), function (array $info) {
         $bindings = $info['bindings'];
         return preg_replace_callback('/\\?/', function () use(&$bindings) {
             $v = current($bindings);
             next($bindings);
             return $this->quote($v);
         }, $info['query']);
     });
     $this->mute(false);
     return $queries;
 }
开发者ID:electro-modules,项目名称:illuminate-database,代码行数:16,代码来源:AbstractSeeder.php


示例20: init

 /**
  * 本体実行前にクラスを初期化する。
  */
 static function init()
 {
     //GET、POST、COOKIEの初期化
     self::$post = $_POST;
     self::$get = $_GET;
     self::$cookie = $_COOKIE;
     if (get_magic_quotes_gpc()) {
         self::$post = map('stripslashes', self::$post);
         self::$get = map('stripslashes', self::$get);
         self::$cookie = map('stripslashes', self::$cookie);
     }
     self::$get = map('rawurldecode', self::$get);
     if (ini_get('mbstring.encoding_translation')) {
         $encode = ini_get('mbstring.internal_encoding');
         $proc = "return mb_convert_encoding(\$str, 'UTF-8', '{$encode}');";
         self::$post = map(create_function('$str', $proc), self::$post);
     }
 }
开发者ID:riaf,项目名称:kinowiki,代码行数:21,代码来源:vars.inc.php



注:本文中的map函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP map_deep函数代码示例发布时间:2022-05-15
下一篇:
PHP manyoulog函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap