Maison > Article > développement back-end > Comment supprimer les valeurs de tableau en double en php
Comment supprimer les valeurs de tableau en double en PHP : ouvrez d'abord le fichier de code PHP correspondant ; puis supprimez les chaînes en double via "array_unique($ordernum);" et enfin affichez le tableau dédupliqué.
L'environnement d'exploitation de cet article : système Windows 7, PHP version 7.1, ordinateur DELL G3
php supprime les valeurs en double du array et renvoie le résultat !
$data = db('order')->field('ordernum')->where(array('user_id' => $user_id))->select();
Format de tableau de requête
array(16) { [0] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [1] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [2] => array(1) { ["ordernum"] => string(18) "190415165656156213" } [3] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [4] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [5] => array(1) { ["ordernum"] => string(18) "190415170056183687" } [6] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [7] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [8] => array(1) { ["ordernum"] => string(18) "190415170345120966" } [9] => array(1) { ["ordernum"] => string(18) "190416174929158053" } [10] => array(1) { ["ordernum"] => string(18) "190416174929158053" } [11] => array(1) { ["ordernum"] => string(18) "190416194457158437" } [12] => array(1) { ["ordernum"] => string(18) "190416194457158437" } [13] => array(1) { ["ordernum"] => string(18) "190416195027154990" } [14] => array(1) { ["ordernum"] => string(18) "190416195027154990" } [15] => array(1) { ["ordernum"] => string(18) "190417124518178758" } } foreach ($data as $k => $v) { $ordernum[] = $v['ordernum']; }
format de tableau ordernum [Apprentissage recommandé : Tutoriel vidéo PHP]
array(16) { [0] => string(18) "190415165656156213" [1] => string(18) "190415165656156213" [2] => string(18) "190415165656156213" [3] => string(18) "190415170056183687" [4] => string(18) "190415170056183687" [5] => string(18) "190415170056183687" [6] => string(18) "190415170345120966" [7] => string(18) "190415170345120966" [8] => string(18) "190415170345120966" [9] => string(18) "190416174929158053" [10] => string(18) "190416174929158053" [11] => string(18) "190416194457158437" [12] => string(18) "190416194457158437" [13] => string(18) "190416195027154990" [14] => string(18) "190416195027154990" [15] => string(18) "190417124518178758" } $ordernum = array_unique($ordernum); //去掉重复的字符串
format de tableau ordernum après déduplication
array(7) { [0] => string(18) "190415165656156213" [3] => string(18) "190415170056183687" [6] => string(18) "190415170345120966" [9] => string(18) "190416174929158053" [11] => string(18) "190416194457158437" [13] => string(18) "190416195027154990" [15] => string(18) "190417124518178758" } foreach ($ordernum as $k => $v) { $new_ordernum[] = $v; //拆分后的重组 }
Nouveau format de tableau généré
array(7) { [0] => string(18) "190415165656156213" [1] => string(18) "190415170056183687" [2] => string(18) "190415170345120966" [3] => string(18) "190416174929158053" [4] => string(18) "190416194457158437" [5] => string(18) "190416195027154990" [6] => string(18) "190417124518178758" }
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!