Thursday, 3 July 2014

PHP Multidimensional Array Search by Column


$result_array = (search($array_list, 'column_name', 'Value'));

function search($array, $key, $value) {
    $results = array();

    if (is_array($array)) {
        if (isset($array[$key]) && $array[$key] == $value) {
            $results[] = $array;
        }

        foreach ($array as $subarray) {
            $results = array_merge($results, search($subarray, $key, $value));
        }
    }

    return $results;
}

No comments:

Post a Comment