Filter Some Keys in Multi-dimensional Arrays in PHP

April 22, 2016

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];
            }
            $i++;
        }

        return $returnArray;
    }

© 2017 Amer Khalid