本文整理汇总了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;
}
示例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));
}
示例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);
}
示例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 . '}';
}
示例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);
}
示例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>';
}
示例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]);
}, []);
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}