Filter Some Keys in Multi Dimensional Arrays in Php

 * Cleans up multi-dimensional arrays.
 * 1st dimension is a simple index
 * 2nd dimension includes the desired keys
 * @param mixed $array
 * @param mixed $keysToInclude
public function cleanUpArray($array, $keysToInclude) {
    $returnArray = array();
    $i = 0;

    foreach($array as $item){
        foreach($keysToInclude as $key){
            $returnArray[$i][$key] = $item[$key];


    return $returnArray;
Published on

Previous post: 4 Hour Body by Tim Ferris

Next post: How to Tell if a Number Is Whole in Php