[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Как сделать массив пустым
Страницы: 1, 2
volter9
stump
Можешь попробовать еще так (для высококачественного извращения):
foreach($array as $i => &$value) {
unset($value);
}


А почему просто не сделать так $this->param = array();?

Ваш код:
foreach( $array as $i => $value )
{
unset( $array[$i] );
}


Ну лучше так во всяком случае:
while ($array) {
array_pop($array);
}


Цитата
Писали люди просто проекты - трах-бах MVC вошло в жизнь. Теперь все делают проекты начиная его через сж...

Нашел что сравнивать, проектирование проекта и чистка массива. :lol:

Может тогда вообще так надо:
Много букаф
class SetTerminator {

public function executeFilter (Set $set) {
$set->filter(function ($value) {
return false;
});
}

public function executePop (Set $set) {
while (!$set->isEmpty()) {
$set->pop();
}
}

}


class Set implements ArrayAccess, Iterator, Countable {

private $data;
private $position = 0;

public function __construct (array $data = []) {
$this->data = [];
}

public function pop () {
return array_pop($this->data);
}

public function filter (Closure $callback) {
$this->data = array_filter($this->data, $callback);
}

public function isEmpty () {
return empty($this->data);
}

// ArrayAccess
public function offsetGet ($offset) {
return $this->offsetExists($offset) ? $this->data[$offset] : false;
}

public function offsetExists ($offset) {
return isset($this->data[$offset]);
}

public function offsetSet ($offset, $value) {
return $this->data[$offset] = $value;
}

public function offsetUnset ($offset) {
unset($this->data[$offset]);
}

// Iterator
public function rewind () {
$this->position = 0;
}

public function current () {
return $this->items[$this->position];
}

public function key () {
return $this->position;
}

public function next () {
$this->position ++;
}

public function valid () {
return isset($this->items[$this->position]);
}

// Countable
public function count () {
return count($this->data);
}

}


$set_one = new Set(range(1, 10));
$set_two = new Set(range(1, 20));

$terminator = new SetTerminator;
$terminator->executeFilter($set_one);
$terminator->executePop($set_two);

var_dump(count($set_one), count($set_two)); // int(0), int(0)

Сразу прошу прощение у товарищей кто считает это слишком пафосным :)

Только это нужно?

_____________
Мой блог
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.