Yearly Archives: 2015

0 1920

Thought I would share a function I wrote to convert property from an a array of objects to a one dimensional array. I ran into this problem because I wanted to select a single field from a DB query into a one dimensional array. I could not figure out how to get that from the DB. All that was available was a object array or array of arrays.

Here is a function to take care of this issue

function objects_to_one_dim($array, $property) {
            $oneDimArray = array();
            foreach($array as $o) {
                $oneDimArray[] = $o -> $property;
            }

            return $oneDimArray;
}

and can be utilized like this

 $newArray = objects_to_one_dim($myObjArray, 'a_property_in_the_object');

23 26256

I have been working on a project in PHP / CodeIgniter that I CANNOT wait to tell you guys about…

I have been developing some sweet CI libraries for this project and have decided to give some of them back to the community.   This is my first PHP open source contribution and my first solo Github project.

The CodeIgniter DataTable library handles all the DB operations for searching, sorting, paging, etc a jQuery DataTable.  The project can be found on GitHub CodeIgniter-DataTables.

This weekend I will be working on a CI example application that uses this library, and will update this post when it is available.  I have some other useful libraries that will be rolling out soon so stay tuned…
***Update: A full working example can be found here