Skip to content

Instantly share code, notes, and snippets.

@tomaskavalek
Created December 16, 2010 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaskavalek/743961 to your computer and use it in GitHub Desktop.
Save tomaskavalek/743961 to your computer and use it in GitHub Desktop.
<?php
public static function init($options = NULL) {
if(is_null($options) || !is_array($options)) return FALSE;
if(is_array(current($options))) {
foreach($options as $option) {
dibi::connect($option, self::CONNECTION . self::$connection++);
}
} else {
dibi::connect($options, self::CONNECTION . self::$connection++);
}
}
$options = array(
array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'test1',
'charset' => 'utf8',
),
array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'test2',
'charset' => 'utf8',
),
);
..::init($options);
$options = array(
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'test1',
'charset' => 'utf8',
);
..::init($options);
@tomaskavalek
Copy link
Author

Lze nějak lépe zjišťovat rozměr pole, abych mohl funkci předat jak array(), tak i array(array(), array(), ...) a nemusel použít break ve foreach a zároveň se nejednalo o psaní další funkce, která by činnost jen zpomalovala? Díky za pomoc.

@norbe
Copy link

norbe commented Dec 17, 2010

co použít reset() a is_array(current())?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment