Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
31
vendor/aiz-packages/combination-generate/src/Providers/CombinationServiceProvider.php
vendored
Normal file
31
vendor/aiz-packages/combination-generate/src/Providers/CombinationServiceProvider.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace AizPackages\CombinationGenerate\Providers;
|
||||
|
||||
use AizPackages\CombinationGenerate\Services\CombinationService;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class CombinationServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(CombinationService::class, function ($app) {
|
||||
return new CombinationService();
|
||||
});
|
||||
}
|
||||
}
|
||||
35
vendor/aiz-packages/combination-generate/src/Services/CombinationService.php
vendored
Normal file
35
vendor/aiz-packages/combination-generate/src/Services/CombinationService.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace AizPackages\CombinationGenerate\Services;
|
||||
|
||||
class CombinationService {
|
||||
|
||||
public function generate_combination($arrays, $i=0)
|
||||
{
|
||||
if (!isset($arrays[$i])) {
|
||||
return array();
|
||||
}
|
||||
if ($i == count($arrays) - 1) {
|
||||
$result = array();
|
||||
foreach ($arrays[$i] as $v) {
|
||||
$result[][] = $v;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// get combinations from subsequent arrays
|
||||
$tmp = $this->generate_combination($arrays, $i + 1);
|
||||
|
||||
$result = array();
|
||||
|
||||
// concat each array from tmp with each element from $arrays[$i]
|
||||
foreach ($arrays[$i] as $v) {
|
||||
foreach ($tmp as $t) {
|
||||
$result[] = is_array($t) ?
|
||||
array_merge(array($v), $t) :
|
||||
array($v, $t);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user