lithium\util\Set::slice PHP Method

slice() public static method

Usage examples: embed:lithium\tests\cases\util\SetTest::testSetSlice(1-4)
public static slice ( array $data, array | string $keys ) : array
$data array
$keys array | string An array of keys or a single key as string
return array An array containing both arrays, having the array with requested keys first and the remainder as second element
    public static function slice(array $data, $keys)
    {
        $removed = array_intersect_key($data, array_fill_keys((array) $keys, true));
        $data = array_diff_key($data, $removed);
        return array($data, $removed);
    }

Usage Example

Beispiel #1
0
 public function run($id = null)
 {
     $id = !is_null($id) ? $id : $this->request->id;
     $model = $this->scaffold['model'];
     $object = $model::first($id);
     if (!$object) {
         $url = array('action' => 'index');
         return $this->redirect($url);
     }
     list($temp, $options) = Set::slice($this->request->data, array('validate', 'strict'));
     switch ($this->request->data['mode']) {
         case 'keep':
             $options['overwrite'] = false;
             break;
         case 'remove':
             $options['prune'] = true;
             break;
     }
     $result = $object->run($options);
     $url = array('action' => 'view', 'args' => array((string) $object->{$model::key()}));
     return $this->redirect($url);
 }
All Usage Examples Of lithium\util\Set::slice