Skip to content

Instantly share code, notes, and snippets.

@mysiar
Last active September 1, 2016 07:10
Show Gist options
  • Save mysiar/6c09aa3daa1e2e02046faffadf74613a to your computer and use it in GitHub Desktop.
Save mysiar/6c09aa3daa1e2e02046faffadf74613a to your computer and use it in GitHub Desktop.
remove element from array
/**
* callback for array_filter to get array without element with $id
*/
class idNotEqual {
private $id;
function __construct($id) {
$this->id = $id;
}
function callback($product) {
return $product->getId() != $this->id;
}
}
public function del($id) {
// array_values recounts indexes from 0
$this->products = array_values(array_filter($this->products, array(new idNotEqual($id), 'callback')));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment