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


PHP flatten函数代码示例

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


在下文中一共展示了flatten函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 <sergio@inbep.com.br>
 *
 * @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


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