<?php
namespace Payment\Utils; class ArrayUtil { public static function paraFilter($para) { $paraFilter = []; foreach ($para as $key => $val) { if ($val === '' || $val === null) { continue; } else { if (!is_array($para[$key])) { $para[$key] = is_bool($para[$key]) ? $para[$key] : trim($para[$key]); } $paraFilter[$key] = $para[$key]; } } return $paraFilter; } public static function removeKeys(array $inputs, $keys) { if (! is_array($keys)) { $keys = explode(',', $keys); } if (empty($keys) || ! is_array($keys)) { return $inputs; } $flag = true; foreach ($keys as $key) { if (array_key_exists($key, $inputs)) { if (is_int($key)) { $flag = false; } unset($inputs[$key]); } } if (! $flag) { $inputs = array_values($inputs); } return $inputs; } public static function arraySort(array $param) { ksort($param); reset($param); return $param; } public static function createLinkstring($para) { if (! is_array($para)) { throw new \Exception('必须传入数组参数'); } reset($para); $arg = ''; foreach ($para as $key => $val) { if (is_array($val)) { continue; } $arg .= $key . '=' . urldecode($val) . '&'; } $arg && $arg = substr($arg, 0, -1); if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $arg = stripslashes($arg); } return $arg; } public static function get(array $arr, $key, $default = '') { if (isset($arr[$key]) && ! empty($arr[$key])) { return $arr[$key]; } return $default; } } 