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

PHP flatten函数代码示例

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

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



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

示例1: generate_gives_to

function generate_gives_to($group_list, $attempt = 0)
{
    $recipients = [];
    $givesto = [];
    $attempt += 1;
    foreach ($group_list as $k1 => $group) {
        $possible_recipients = array_merge(array_slice($group_list, 0, $k1), array_slice($group_list, $k1 + 1));
        $possible_recipients = array_diff(flatten($possible_recipients), $recipients);
        foreach ($group as $k2 => $person) {
            if (empty($possible_recipients)) {
                if ($attempt < 10) {
                    return generate_gives_to($group_list, $attempt);
                } else {
                    echo " - INCOMPLETE SOLUTION - ";
                }
            }
            $k = array_rand($possible_recipients);
            $givesto[$person] = $possible_recipients[$k];
            $recipients[] = $possible_recipients[$k];
            unset($possible_recipients[$k]);
        }
    }
    fancy_print($givesto);
    return $givesto;
}
开发者ID:smithworx,项目名称:givesto,代码行数:25,代码来源:givesto.php


示例2: split_definitions

function split_definitions($defs)
{
    if (is_array($defs)) {
        return flatten(array_map("split_definitions", $defs));
    }
    return array_map("trim", preg_split("/[,;\n]/", $defs));
}
开发者ID:NasalMusician,项目名称:Pantheum,代码行数:7,代码来源:translation.php


示例3: test_variadic

 function test_variadic()
 {
     $result = flatten([[1, 2], [3, 4]], [[5, 6]]);
     $expect = [1, 2, 3, 4, 5, 6];
     $actual = iterator_to_array($result, false);
     $this->assertEquals($expect, $actual);
 }
开发者ID:morrisonlevi,项目名称:algorithm,代码行数:7,代码来源:FlattenTest.php


示例4: compile_node

 function compile_node($options)
 {
     $idt1 = $options['indent'] . TAB;
     $idt2 = $options['indent'] = $idt1 . TAB;
     $code = $this->tab . 'switch (' . ($this->subject ? $this->subject->compile($options, LEVEL_PAREN) : 'false') . ") {\n";
     foreach ($this->cases as $i => $case) {
         list($conditions, $block) = $case;
         foreach (flatten(array($conditions)) as $cond) {
             if (!$this->subject) {
                 $cond = $cond->invert();
             }
             $code .= $idt1 . 'case ' . $cond->compile($options, LEVEL_PAREN) . ":\n";
         }
         if ($body = $block->compile($options, LEVEL_TOP)) {
             $code .= $body . "\n";
         }
         if ($i === count($this->cases) - 1 && !$this->otherwise) {
             break;
         }
         $expr = $this->last_non_comment($block->expressions);
         if ($expr instanceof yy_Return || $expr instanceof yy_Literal && $expr->jumps() && '' . $expr->value !== 'debugger') {
             continue;
         }
         $code .= $idt2 . "break;\n";
     }
     if ($this->otherwise && count($this->otherwise->expressions)) {
         $code .= $idt1 . "default:\n" . $this->otherwise->compile($options, LEVEL_TOP) . "\n";
     }
     return $code . $this->tab . '}';
 }
开发者ID:TeigneuX,项目名称:php-websocket,代码行数:30,代码来源:switch.php


示例5: generate_gives_to

function generate_gives_to($group_list, $fancy_print = true, $attempt = 0)
{
    $recipients = [];
    $givesto = [];
    $attempt += 1;
    foreach ($group_list as $k1 => $group) {
        $possible_recipients = array_merge(array_slice($group_list, 0, $k1), array_slice($group_list, $k1 + 1));
        $possible_recipients = array_diff(flatten($possible_recipients), $recipients);
        foreach ($group as $k2 => $person) {
            if (empty($possible_recipients)) {
                if ($attempt < 10) {
                    return generate_gives_to($group_list, $fancy_print, $attempt);
                } else {
                    return false;
                }
            }
            $k = array_rand($possible_recipients);
            $givesto[trim($person)] = trim($possible_recipients[$k]);
            $recipients[] = $possible_recipients[$k];
            unset($possible_recipients[$k]);
        }
    }
    //echo fancy_print($givesto);
    //return $givesto;
    return $fancy_print ? fancy_print($givesto) : json_encode($givesto);
}
开发者ID:smithworx,项目名称:givesto-app,代码行数:26,代码来源:givesto.php


示例6: render

 function render()
 {
     JS::loadjQuery();
     JS::lib('viewslider');
     JS::raw('$(function(){$("div.viewslider-view").closest(".formdiv").viewslider();});');
     Head::add('viewslider/viewslider', 'css-lib');
     return '<div class="formsection viewslider-view"><h3>' . $this->header . '</h3>' . implode('', flatten($this->elements)) . '</div>';
 }
开发者ID:jonatanolofsson,项目名称:solidba.se,代码行数:8,代码来源:Formsection.php


示例7: flatten

/**
 * @author Sérgio Rafael Siqueira <[email protected]>
 *
 * @param array $xs
 *
 * @return mixed
 */
function flatten(array $xs)
{
    return array_reduce($xs, function ($carry, $x) {
        if (is_array($x)) {
            return array_merge($carry, flatten($x));
        }
        return array_merge($carry, [$x]);
    }, []);
}
开发者ID:sergiors,项目名称:functional,代码行数:16,代码来源:flatten.php


示例8: trace

function trace()
{
    global $action, $activities, $scheduling;
    echo '<br>action: ' . $action;
    echo '<br>activities:';
    print_r($activities);
    echo '<br>scheduling:';
    print_r($scheduling);
    echo '<br>flattened activities: ' . count(flatten($activities));
    exit;
}
开发者ID:JordiCruells,项目名称:mtbd,代码行数:11,代码来源:scheduling.php


示例9: test_show

 /**
  * @preserveGlobalState disabled
  * @runInSeparateProcess
  */
 public function test_show()
 {
     Hm_Msgs::add('msg two');
     $this->assertTrue(strstr(flatten(join('', Hm_Msgs::show('return'))), 'msgtwo') !== false);
     ob_start();
     Hm_Msgs::show();
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertTrue(strlen($output) > 0);
     Hm_Msgs::show('log');
 }
开发者ID:GordonDiggs,项目名称:hm3,代码行数:15,代码来源:output.php


示例10: trace

function trace()
{
    global $action, $activities, $workshop;
    echo '<br>action: ' . $action;
    echo '<br>activities:';
    print_r($activities);
    echo '<br>workshop:';
    print_r($workshop);
    echo '<br>flattened activities: ' . count(flatten($activities));
    exit;
}
开发者ID:JordiCruells,项目名称:mtbd,代码行数:11,代码来源:workshop.php


示例11: flatten

 static function flatten(array $array)
 {
     $flattened = array();
     foreach ($array as $k => $v) {
         if (is_array($v)) {
             $flattened = array_merge($flattened, flatten($v));
         } else {
             $flattened[] = $v;
         }
     }
     return $flattened;
 }
开发者ID:mdb-webdev,项目名称:Fourstatic,代码行数:12,代码来源:Helpers.php


示例12: flatten

function flatten($arg, &$results = array())
{
    if (is_array($arg)) {
        foreach ($arg as $a => $p) {
            if (is_array($p)) {
                flatten($p, $results);
            } else {
                $results[] = $a;
            }
        }
    }
    return $results;
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:13,代码来源:init_categorylinkstop.php


示例13: flatten

function flatten($ary)
{
    $result = array();
    foreach ($ary as $x) {
        if (is_array($x)) {
            // append flatten($x) onto $result
            array_splice($result, count($result), 0, flatten($x));
        } else {
            $result[] = $x;
        }
    }
    return $result;
}
开发者ID:pombredanne,项目名称:fuzzer-fat-fingers,代码行数:13,代码来源:FlatList.php


示例14: flatten

function flatten($array, $return = array())
{
    foreach ($array as $k => $v) {
        if (is_array($v)) {
            $return = flatten($v, $return);
        } else {
            if ($v) {
                $return[] = $v;
            }
        }
    }
    return $return;
}
开发者ID:ashleycam3ron,项目名称:functions,代码行数:13,代码来源:flatten.php


示例15: flatten

function flatten($array)
{
    $l = [];
    if (is_array($array)) {
        foreach ($array as $v) {
            if (is_array($v)) {
                $l = array_merge($l, flatten($v));
            } else {
                $l[] = $v;
            }
        }
    }
    return $l;
}
开发者ID:appsuite-com-au,项目名称:gossamer,代码行数:14,代码来源:lispfuns.php


示例16: __call

 public function __call($name, $arguments)
 {
     error_log("[FreesideSelfService] {$name} called, sending to " . $this->URL);
     $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.{$name}", flatten($arguments[0]));
     $context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
     $file = file_get_contents($this->URL, false, $context);
     $response = xmlrpc_decode($file);
     if (xmlrpc_is_fault($response)) {
         trigger_error("[FreesideSelfService] XML-RPC communication error: {$response['faultString']} ({$response['faultCode']})");
     } else {
         //error_log("[FreesideSelfService] $response");
         return $response;
     }
 }
开发者ID:carriercomm,项目名称:Freeside,代码行数:14,代码来源:freeside.class.new.php


示例17: flatten

function flatten($array, $path = "")
{
    $result = array();
    foreach ($array as $key => $value) {
        $fullkey = empty($path) ? $key : $path . "." . $key;
        if (is_array($value)) {
            $result = array_merge($result, flatten($value, $fullkey));
        } elseif (is_numeric($value)) {
            $result[$fullkey] = (string) $value;
        } else {
            $result[$fullkey] = '"' . $value . '"';
        }
    }
    return $result;
}
开发者ID:BACKUPLIB,项目名称:mwenhanced,代码行数:15,代码来源:admin.config.php


示例18: flatten

/**
 * Flattens out a multi-dimentional array
 *
 * @params array $elements A multi-dimentional array
 * @params int $depth Index showing the array depth
 *
 * @return array $result Returns flattened array
 */
function flatten($elements, $depth)
{
    $result = array();
    foreach ($elements as $key => &$element) {
        if (isset($depth) == true) {
            $element['depth'] = $depth;
        }
        if (isset($element['children'])) {
            $children = $element['children'];
            unset($element['children']);
        } else {
            $children = null;
        }
        $result[$key] = $element;
        if (isset($children)) {
            $result = array_merge($result, flatten($children, $depth + 1));
        }
    }
    return $result;
}
开发者ID:pericles-project,项目名称:MICE,代码行数:28,代码来源:flattenHelper.php


示例19: each_child

 function each_child($func)
 {
     if (!$this->children) {
         return $this;
     }
     foreach ($this->children as $i => $attr) {
         if (isset($this->{$attr}) && $this->{$attr}) {
             foreach (flatten(array($this->{$attr})) as $i => $child) {
                 if ($func($child) === FALSE) {
                     break 2;
                 }
             }
         }
     }
     return $this;
 }
开发者ID:jkrecek,项目名称:coffeescript-php,代码行数:16,代码来源:Base.php


示例20: walk_body

 function walk_body($name, $options)
 {
     $self = $this;
     $this->traverse_children(FALSE, function ($child) use($name, $options, &$self) {
         if ($child instanceof yy_Class) {
             return FALSE;
         }
         if ($child instanceof yy_Block) {
             foreach ($exps = $child->expressions as $i => $node) {
                 if ($node instanceof yy_Value && $node->is_object(TRUE)) {
                     $exps[$i] = $self->add_properties($node, $name, $options);
                 }
             }
             $child->expressions = $exps = flatten($exps);
         }
     });
 }
开发者ID:musicsnap,项目名称:Cdoco_Yaf_Ext,代码行数:17,代码来源:Class.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP flattenText函数代码示例发布时间:2022-05-15
下一篇:
PHP flashdata函数代码示例发布时间: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