flat() public static méthode

Flattens a multi dimensional bindings array for use with genSlots().
public static flat ( array $array, $result = [] ) : array
$array array array to flatten
Résultat array
Exemple #1
0
Fichier : rb.php Projet : WTer/NJB
 function array_flatten($array)
 {
     return \RedBeanPHP\Facade::flat($array);
 }
Exemple #2
0
 /**
  * Test forming IN-clause using genSlots and flat.
  *
  * @return void
  */
 public function testINClause()
 {
     list($flowers, $shop) = R::dispenseAll('flower*4,shop');
     $flowers[0]->color = 'red';
     $flowers[1]->color = 'yellow';
     $flowers[2]->color = 'blue';
     $flowers[3]->color = 'purple';
     $flowers[0]->price = 10;
     $flowers[1]->price = 15;
     $flowers[2]->price = 20;
     $flowers[3]->price = 25;
     $shop->xownFlowerList = $flowers;
     R::store($shop);
     $colors = array('red', 'yellow');
     $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 100))));
     asrt($result, 'red,yellow');
     $colors = array('red', 'yellow');
     $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 10))));
     asrt($result, '');
     $colors = array('red', 'yellow');
     $result = $this->getColors(R::find('flower', ' color IN (' . R::genSlots($colors) . ' ) AND price < ?', R::flat(array($colors, 15))));
     asrt($result, 'red');
     asrt(json_encode(R::flat(array('a', 'b', 'c'))), '["a","b","c"]');
     asrt(json_encode(R::flat(array('a', array('b'), 'c'))), '["a","b","c"]');
     asrt(json_encode(R::flat(array('a', array('b', array('c'))))), '["a","b","c"]');
     asrt(json_encode(R::flat(array(array('a', array('b', array(array('c'))))))), '["a","b","c"]');
     asrt(json_encode(R::flat(array('a', 'b', 'c', array()))), '["a","b","c"]');
     asrt(genslots(array(1, 2)), '?,?');
     asrt(json_encode(array_flatten(array(array('a', array('b', array(array('c'))))))), '["a","b","c"]');
     asrt(genslots(array(1, 2), 'IN (%s) AND'), 'IN (?,?) AND');
     asrt(genslots(array(), ' IN (%s) AND '), '');
     $colors = array('blue', 'purple', 'red');
     $flowers = R::find('flower', genslots($colors, ' color IN (%s) AND ') . ' price > ? ', array_flatten(array($colors, 11)));
     asrt($this->getColors($flowers), 'blue,purple');
     $flowers = R::find('flower', genslots(array(), ' color IN (%s) AND ') . ' price > ? ', array_flatten(array(array(), 11)));
     asrt($this->getColors($flowers), 'blue,purple,yellow');
     $flowers = R::find('flower', ' id > 0 AND ' . genslots($colors, ' color IN (%s) AND ') . ' price > ? ', array_flatten(array($colors, 11)));
     asrt($this->getColors($flowers), 'blue,purple');
     $flowers = R::find('flower', ' id > 0 AND ' . genslots(array(), ' color IN (%s) AND ') . ' price > ? ', array_flatten(array(array(), 11)));
     asrt($this->getColors($flowers), 'blue,purple,yellow');
 }