Filter an array of objects

Quite often I might have an array of objects, be it from a db query or some json object, and I want to filter that list in a particular way.  Lots of times I would find myself doing the same old thing; creating a new array, looping and looping until all I had left was what matched my filter.

I’m sure you’ve been there and done it a thousand times, too.

Well, this little function should help that task out a lot!

Say I had an array of people objects and wanted only those people who’s name was Bob and was aged 35, I could do something as simple as:

$filtered = ofilter($items, ['name' => 'Bob', 'age' => 35]);

Or maybe something a little tricker; I wanted to get anyone whose age was between 18 and 35 (inclusive):

$filtered = ofilter($items, ['age' => function($age) { return ($age >= 18 && $age < = 35); }]);

Pretty easy, eh?

Here’s the code – it’s a GitHub gist, so feel free to fork and improve!
Continue reading “Filter an array of objects”

Did you like this? Share it:

First “proper” thing made with a hammer and anvil

On this past weekend the family and I went camping with a few friends, and a lovely time was had by all (despite a couple bee stings and a bad face-plant by someone into a pavement). While taking down the tent we realised that our tent peg puller was a little weak and we even struggled with it to pull a couple of the tougher pegs.

This seemed like an opportunity for improvement and an excuse to make something in the forge!

Continue reading “First “proper” thing made with a hammer and anvil”

Did you like this? Share it:

First blacksmithing session

I had my first blacksmithing session last week, and it was probably the most fun I’ve had with a hammer and metal in… well, I’m too old now to remember how long ago things were. But a long time, let me tell you.

At first I learned how to draw down to a square point, and then built on that to make a rounded point. After I did those, I created a square-pointed scroll and then fish-tailed scroll.

OK, so artistically I’m never really going to do wonders (I’ll be the first to admit I’m not exactly talented in the artistic department!) But I could really get to like doing the occasional bit of smithing and can’t wait to get my anvil and forge set up and buy some hammers and metal stock to practise.

Did you like this? Share it: