Thursday, May 16, 2013

little things BIG time saving (Some important php Functions)



1. array_filter()
simply remove null/empty values froma an array.
$entry = array(
             0 => 'foo',
             1 => false,
             2 => -1,
             3 => null,
             4 => ''
          );
print_r(array_filter($entry));
OutPUT
Array
(
    [0] => foo
    [2] => -1
)

2. readCSV
this function simply takes csv filename(with path) and return an array
function readCSV($csvFile) {
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle)) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    return array_filter($line_of_text);        
}