interface Entity {
/**
* Property setter
*
* @param string $name Set property
*
* @return Entity (return $this;)
*/
public function setName(string $name): Entity;
/**
* Property getter
*
* @param null|string $default Default value of property
*
* @return string Property value
*/
public function getName(?string $default = null): string;
}
interface Entity {
/**
* Property setter and getter in one method
*
* @param null|string $name Set property value or get on $name = null
*
* @return Entity|string
*/
public function name(?string $name = null);
}
function crossJoin($array)
{
$result = [];
$current = array_splice($array, -1);
foreach ($current as $key => $values) {
foreach ((array) $values as $value) {
if (empty($array)) {
array_push($result, [$key => $value]);
} else {
foreach (crossJoin($array) as $temp) {
array_push($result, array_merge([$key => $value], $temp));
}
}
}
}
return $result;
}
crossJoin($a);
function splitter($subject, $n, array $symbols) {
return implode(array_map(function ($part) use ($n, $symbols) {
if (strlen($part) === $n) {
$part .= $symbols[array_rand($symbols)];
}
return $part;
}, str_split($subject, $n)));
}
echo splitter('0000000000000000000000', rand(1, 3), [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);