Skip to content

Instantly share code, notes, and snippets.

@wowo
Created November 14, 2010 00:58
Show Gist options
  • Save wowo/675789 to your computer and use it in GitHub Desktop.
Save wowo/675789 to your computer and use it in GitHub Desktop.
Easy way of removing new lines in every attribute of an object - with closures in PHP 5.3
<?php
class Operation
{
public $dateOperation;
public $datePosting;
public $type;
public $description;
public $priceOriginalCurrency;
public $pricePln;
public function removeNewLines()
{
array_walk($this, function(&$value) {
$value = str_replace("\n", "", $value);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment