Skip to content

Instantly share code, notes, and snippets.

View mattkirwan's full-sized avatar

Matt Kirwan mattkirwan

View GitHub Profile
@mattkirwan
mattkirwan / flattenArray.php
Created January 29, 2013 19:20
Uses PHP's built in SPL Array Iterators to quickly spin through a multidimensional array and return a 'flattened' output.
<?php
function flattenArray( array $array )
{
$returned_array = array();
foreach( new \RecursiveIteratorIterator( new \RecursiveArrayIterator($array) ) as $key => $value )
{
$returned_array[] = $value;
}
@mattkirwan
mattkirwan / CSV_Ripper.php
Created January 11, 2013 20:29
This gist uses PHP's built in SplFileObject class to loop through .csv file and pretty much do what you want with each row of data. Probably one of my most used snippets of code.
<?php
$file = 'data.csv';
try {
$csv = new SplFileObject($file, 'r');
} catch (RuntimeException $e) {
printf("Error opening .csv: %s\n", $e->getMessage());
}
@mattkirwan
mattkirwan / ServiceProviderDB.php
Created December 12, 2012 14:51
ServiceProvider DB
<?php
// Service Provider
$app->register(new Via\Content\ContentServiceProvider());
// Route
$app->get('/{id}', function(Doctrine\DBAL\Connection $db) use ($app) {
return $app['content.id_checker']($db);
});
// and in .... ContentServiceProvider
@mattkirwan
mattkirwan / AvailableTask_MattKirwan
Created December 5, 2012 21:45
AvailableTask value attribute - possible type inconsistencies
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="test">
<property name="dir" value="../test_directory" />
<target name="test">
<echo message="Test 1:" />
<echo message="--------------------" />