当前位置: 首页>>代码示例>>PHP>>正文


PHP Arr::push方法代码示例

本文整理汇总了PHP中Arr::push方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::push方法的具体用法?PHP Arr::push怎么用?PHP Arr::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arr的用法示例。


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

示例1: function

        if ($self->hasOwnProperty($i)) {
            $result = $fn->call($context, $self->get($i), (double) $i, $self);
            $results->set($i, $result);
        }
    }
    return $results;
}, 'filter' => function ($fn, $context = null) {
    $self = Func::getContext();
    $results = new Arr();
    $len = $self->length;
    for ($i = 0; $i < $len; $i++) {
        if ($self->hasOwnProperty($i)) {
            $item = $self->get($i);
            $result = $fn->call($context, $item, (double) $i, $self);
            if (is($result)) {
                $results->push($item);
            }
        }
    }
    return $results;
}, 'sort' => function ($fn = null) {
    $self = Func::getContext();
    if ($fn instanceof Func) {
        $results = $self->toArray();
        $comparator = function ($a, $b) use(&$fn) {
            return $fn->call(null, $a, $b);
        };
        uasort($results, $comparator);
    } else {
        $results = array();
        $len = $self->length;
开发者ID:mk-pmb,项目名称:js2php,代码行数:31,代码来源:Array.php

示例2: Arr

    $self = Func::getContext();
    $str = $self->value;
    if (!$regex instanceof RegExp) {
        $regex = $RegExp->construct($regex);
    }
    if (!$regex->globalFlag) {
        return $regex->callMethod('exec', $str);
    }
    $results = new Arr();
    $index = 0;
    $preg = $regex->toString(true);
    while (preg_match($preg, $str, $matches, PREG_OFFSET_CAPTURE, $index) === 1) {
        $foundAt = $matches[0][1];
        $foundStr = $matches[0][0];
        $index = $foundAt + strlen($foundStr);
        $results->push($foundStr);
    }
    return $results;
}, 'replace' => function ($search, $replace) {
    $self = Func::getContext();
    $str = $self->value;
    $isRegEx = $search instanceof RegExp;
    $limit = $isRegEx && $search->globalFlag ? -1 : 1;
    $search = $isRegEx ? $search->toString(true) : to_string($search);
    if ($replace instanceof Func) {
        if ($isRegEx) {
            $count = 0;
            $offset = 0;
            $result = array();
            $success = null;
            while (($limit === -1 || $count < $limit) && ($success = preg_match($search, $str, $matches, PREG_OFFSET_CAPTURE, $offset))) {
开发者ID:mk-pmb,项目名称:js2php,代码行数:31,代码来源:String.php

示例3: array

RegExp::$protoMethods = array('exec' => function ($str) {
    $self = Func::getContext();
    $str = to_string($str);
    //todo $offset
    $offset = 0;
    $result = preg_match($self->toString(true), $str, $matches, PREG_OFFSET_CAPTURE, $offset);
    if ($result === false) {
        throw new Ex(Error::create('Error executing Regular Expression: ' . $self->toString()));
    }
    if ($result === 0) {
        return Object::$null;
    }
    $index = $matches[0][1];
    $self->set('lastIndex', (double) ($index + strlen($matches[0][0])));
    $arr = new Arr();
    foreach ($matches as $match) {
        $arr->push($match[0]);
    }
    $arr->set('index', (double) $index);
    $arr->set('input', $str);
    return $arr;
}, 'test' => function ($str) {
    $self = Func::getContext();
    $result = preg_match($self->toString(true), to_string($str));
    return $result !== false;
}, 'toString' => function () {
    $self = Func::getContext();
    return $self->toString(false);
});
RegExp::$protoObject = new Object();
RegExp::$protoObject->setMethods(RegExp::$protoMethods, true, false, true);
开发者ID:mk-pmb,项目名称:js2php,代码行数:31,代码来源:RegExp.php

示例4: Date

     $result->set('dateLastAccessed', new Date($stat['atime'] * 1000));
     $result->set('dateLastModified', new Date($stat['mtime'] * 1000));
     $result->set('type', $isDir ? 'directory' : 'file');
     if (!$isDir) {
         $result->set('size', (double) $stat['size']);
     } else {
         if ($deep) {
             $size = 0.0;
             $children = new Arr();
             foreach (scandir($fullPath) as $item) {
                 if ($item === '.' || $item === '..') {
                     continue;
                 }
                 $child = $helpers['getInfo']($fullPath . DIRECTORY_SEPARATOR . $item, $deep);
                 $size += $child->get('size');
                 $children->push($child);
             }
             $result->set('children', $children);
             $result->set('size', $size);
         } else {
             $result->set('size', 0.0);
         }
     }
     return $result;
 }, 'deleteFile' => function ($fullPath) use(&$helpers) {
     try {
         $result = unlink($fullPath);
     } catch (Exception $e) {
         $helpers['handleException']($e, $fullPath);
     }
     //fallback for if set_error_handler didn't do it's thing
开发者ID:mk-pmb,项目名称:js2php,代码行数:31,代码来源:fs.php

示例5: function

$JSON = call_user_func(function () {
    $decode = function ($value) use(&$decode) {
        if ($value === null) {
            return Object::$null;
        }
        $type = gettype($value);
        if ($type === 'integer') {
            return (double) $value;
        }
        if ($type === 'string' || $type === 'boolean' || $type === 'double') {
            return $value;
        }
        if ($type === 'array') {
            $result = new Arr();
            foreach ($value as $item) {
                $result->push($decode($item));
            }
        } else {
            $result = new Object();
            foreach ($value as $key => $item) {
                if ($key === '_empty_') {
                    $key = '';
                }
                $result->set($key, $decode($item));
            }
        }
        return $result;
    };
    $escape = function ($str) {
        return str_replace("\\/", "/", json_encode($str));
    };
开发者ID:mk-pmb,项目名称:js2php,代码行数:31,代码来源:JSON.php


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