<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; class ArrayUtil { public static function sequenceEqual($wRmxV, $L1ZAU) { goto hdXxz; hdXxz: sort($wRmxV); goto ZZBT9; ZZBT9: sort($L1ZAU); goto Ra345; Ra345: return json_encode($wRmxV) == json_encode($L1ZAU); goto pDaZ9; pDaZ9: } public static function equal($wRmxV, $L1ZAU, $sk8MQ = null, $jf_bV = false) { goto KX1X3; KX1X3: if (null === $sk8MQ) { $sk8MQ = array_merge(array_keys($wRmxV), array_keys($L1ZAU)); } goto H_zVe; H_zVe: foreach ($sk8MQ as $U9AsU) { goto XMOTu; Iafxo: if ($jf_bV) { if ($wRmxV[$U9AsU] !== $L1ZAU[$U9AsU]) { return false; } } else { if ($wRmxV[$U9AsU] != $L1ZAU[$U9AsU]) { return false; } } goto vSecp; ZHnuc: if (!array_key_exists($U9AsU, $L1ZAU)) { return false; } goto Iafxo; XMOTu: if (!array_key_exists($U9AsU, $wRmxV)) { return false; } goto ZHnuc; vSecp: } goto NN15J; NN15J: return true; goto p9k0J; p9k0J: } public static function flatItemsByKey(&$NjVHK, $m1RYi) { goto ehP_Y; lWwZo: foreach ($NjVHK as $Nrp0b) { $yw7NX[] = $Nrp0b[$m1RYi]; } goto UtMAJ; ehP_Y: $yw7NX = array(); goto lWwZo; UtMAJ: return $yw7NX; goto ocdxo; ocdxo: } public static function keepKeys($SP0Zs, $sk8MQ) { goto FXuu1; MkH0g: if (empty($sk8MQ) || empty($SP0Zs)) { return $g7W6s; } goto wiosd; a5lzQ: return $g7W6s; goto N0lhV; ywn9D: if (is_string($sk8MQ)) { $sk8MQ = array($sk8MQ); } goto oc3zn; oc3zn: $g7W6s = array(); goto MkH0g; wiosd: foreach ($SP0Zs as $U9AsU => $ohYVl) { if (in_array($U9AsU, $sk8MQ)) { $g7W6s[$U9AsU] = $ohYVl; } } goto a5lzQ; FXuu1: if (empty($SP0Zs)) { return $SP0Zs; } goto ywn9D; N0lhV: } public static function keepItemsKeys(&$NjVHK, $sk8MQ) { goto bklWp; jEClQ: if (empty($sk8MQ)) { return $g7W6s; } goto gtqIA; gtqIA: foreach ($NjVHK as $ohYVl) { goto WGY23; gpcsH: $g7W6s[] = $Nrp0b; goto MSxYJ; e_HqE: foreach ($ohYVl as $mh8aM => $WHWZ8) { if (in_array($mh8aM, $sk8MQ)) { $Nrp0b[$mh8aM] = $WHWZ8; } } goto gpcsH; WGY23: $Nrp0b = array(); goto e_HqE; MSxYJ: } goto vLhXR; vLhXR: return $g7W6s; goto xp9Pg; bklWp: $g7W6s = array(); goto jEClQ; xp9Pg: } public static function removeKeys($SP0Zs, $sk8MQ) { goto wiryz; VV_1U: return $g7W6s; goto CZyEs; wiryz: if (empty($sk8MQ) || empty($SP0Zs)) { return $SP0Zs; } goto mhi9x; mhi9x: $g7W6s = array(); goto KUFjw; KUFjw: foreach ($SP0Zs as $U9AsU => $ohYVl) { if (!in_array($U9AsU, $sk8MQ)) { $g7W6s[$U9AsU] = $ohYVl; } } goto VV_1U; CZyEs: } public static function renameItemsKey(&$NjVHK, $vVL_0) { foreach ($NjVHK as $U9AsU => $ohYVl) { foreach ($vVL_0 as $JVYH8 => $x09Du) { $NjVHK[$U9AsU][$x09Du] = $NjVHK[$U9AsU][$JVYH8]; unset($NjVHK[$U9AsU][$JVYH8]); } } } public static function random($NjVHK) { goto Eel6h; Eel6h: if (empty($NjVHK)) { return null; } goto J7vcz; ojVoY: return $NjVHK[array_rand($NjVHK)]; goto wakJg; J7vcz: if (count($NjVHK) == 1) { return $NjVHK[0]; } goto ojVoY; wakJg: } public static function trimItems($NjVHK) { goto xkbO8; xkbO8: $g7W6s = array(); goto LjqZ4; v1ARv: return $g7W6s; goto HKpTR; LjqZ4: foreach ($NjVHK as $U9AsU => $ohYVl) { if (is_array($ohYVl)) { $g7W6s[$U9AsU] = self::trims($ohYVl); } else { $g7W6s[$U9AsU] = trim($ohYVl); } } goto v1ARv; HKpTR: } public static function isAllEmpty($NjVHK) { goto T7gkc; miW6W: for ($K3Ni_ = 0; $K3Ni_ < count($NjVHK); $K3Ni_++) { $ohYVl = trim($NjVHK[$K3Ni_]); if (!empty($ohYVl)) { return false; } } goto VsCy3; T7gkc: if (empty($NjVHK) || !is_array($NjVHK)) { return true; } goto miW6W; VsCy3: return true; goto B7_KB; B7_KB: } public static function sortByKey($NjVHK, $m1RYi = 'sort', $c1OmT = 'asc') { usort($NjVHK, function ($kaveK, $ieIhf) use($m1RYi, $c1OmT) { if ($kaveK[$m1RYi] == $ieIhf[$m1RYi]) { return 0; } $uotzZ = $kaveK[$m1RYi] > $ieIhf[$m1RYi] ? 1 : -1; return $c1OmT == 'asc' ? $uotzZ : -$uotzZ; }); return $NjVHK; } public static function keep(&$NjVHK, $DJshY = 10) { goto lQy1S; j2sX1: $evEz0 = 0; goto g9aFL; g9aFL: foreach ($NjVHK as $U9AsU => $ohYVl) { goto u7meI; dcjKr: $evEz0++; goto uwzj2; uwzj2: if ($evEz0 >= $DJshY) { return $RgydD; } goto f7dBf; u7meI: $RgydD[$U9AsU] = $ohYVl; goto dcjKr; f7dBf: } goto w03rH; lQy1S: $RgydD = array(); goto j2sX1; w03rH: return $RgydD; goto RUQRM; RUQRM: } public static function diff(array $zW60P, array $oV1Ds) { goto V26co; mxRcy: $h48cP = array(); goto BGdL8; BGdL8: foreach ($oV1Ds as $bPX0o) { if (!in_array($bPX0o, $zW60P)) { $h48cP[] = $bPX0o; } } goto M6ilu; V26co: $yTCeu = array(); goto mxRcy; V2b6u: return array($h48cP, $yTCeu); goto RrP7q; M6ilu: foreach ($zW60P as $bPX0o) { if (!in_array($bPX0o, $oV1Ds)) { $yTCeu[] = $bPX0o; } } goto V2b6u; RrP7q: } }