尊龙凯时人生就是搏

laravel Êý×éÒƳýÏàͬ

laravel ÊÇÒ»¿î¹ãÊܽӴýµÄ php ¿ª·¢¿ò¼Ü £¬ÌṩÁËÐí¶àÀû±ãµÄ¸¨Öúº¯Êý¡£ÔÚ¿ª·¢Àú³ÌÖÐ £¬¾­³ £»áÓÐÐèÒªÒƳýÊý×éÖÐÏàֵͬµÄÇéÐΡ£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓà laravel ×Ô´øµÄ¸¨Öúº¯ÊýÀ´ÊµÏÖÕâ¸ö¹¦Ð§¡£

ʹÓà array_unique º¯Êý

array_unique º¯ÊýÊÇ PHP ×Ô´øµÄÒ»¸öº¯Êý £¬¿ÉÒÔÓÃÀ´ÒƳýÊý×éÖеÄÖظ´Öµ¡£Ê¹ÓÃÕâ¸öº¯ÊýºÜÊǼòÆÓ £¬Ö»ÐèÒª½«ÐèҪȥÖصÄÊý×é×÷Ϊ²ÎÊý´«Èë¼´¿É¡£

ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öÊý×é $arr £¬ËüµÄÔªËØÈçÏ£º

$arr = [1, 2, 2, 3, 4, 4, 4, 5];

µÇ¼ºó¸´ÖÆ

ÈôÊÇÒªÒƳýÆäÖеÄÖظ´ÔªËØ £¬¿ÉÒÔʹÓà array_unique º¯Êý£º

$uniqueArr = array_unique($arr);

µÇ¼ºó¸´ÖÆ

ÕâÑù £¬$uniqueArr ¾ÍÊÇÒ»¸öÈ¥ÖغóµÄÊý×é¡£

¿ÉÊÇÕâÖÖÒªÁìÓÐÒ»¸öÈõµã £¬¼´ÒƳýºóµÄÊý×éÔªËØϱê»á±»ÖØÖà £¬Òò´Ë²»ÊÊÓÃÓÚÐèÒª±£´æÔ­ÓÐϱêµÄÇéÐΡ£

ʹÓà Laravel µÄ¸¨Öúº¯Êý

Laravel ÌṩÁËһϵÁÐÀû±ãÊÊÓõĸ¨Öúº¯Êý £¬ÆäÖоͰüÀ¨ÓÃÓÚ´¦ÀíÊý×éµÄº¯Êý¡£ÆäÖÐÒ»¸ö³£Óõĺ¯ÊýÊÇ collect º¯Êý £¬¿ÉÒÔ½«Ò»¸öÊý×é°üװΪÜöÝÍ £¬È»ºóʹÓÃÜöÝÍÌṩµÄÒªÁìÀ´¾ÙÐвÙ×÷¡£

ʹÓà collect º¯Êý½«Êý×é·âװΪÜöÝÍ£º

$collection = collect($arr);

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

½Ó×Å £¬ÎÒÃÇ¿ÉÒÔʹÓà unique ÒªÁìÀ´ÒƳýÏàͬԪËØ£º

$uniqueCollection = $collection->unique();

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÕâÑù £¬$uniqueCollection ¾ÍÊÇÒ»¸öÈ¥ÖغóµÄÜöÝÍ¡£

Óë array_unique º¯Êý²î±ðµÄÊÇ £¬Ê¹Óà unique ÒªÁìºó £¬±£´æÁËÔ­ÓÐÊý×éÔªËصÄϱê¡£ÈôÊÇÐèÒª·µ»Ø²»´øϱêµÄÊý×é £¬¿ÉÒÔʹÓà values ÒªÁ죺

$uniqueArr = $uniqueCollection->values()->all();

µÇ¼ºó¸´ÖÆ

ÕâÑù £¬$uniqueArr ¾ÍÊÇÒ»¸öÈ¥Öغó £¬²»´øÓÐϱêµÄÊý×é¡£

ʹÓà Laravel µÄ Collection Àà

³ýÁËʹÓø¨Öúº¯Êý £¬Laravel »¹ÌṩÁËÁíÍâÒ»ÖÖÔ½·¢Àû±ãµÄÒªÁì £¬×ÝÈ»Óà Collection Àà¡£

Collection ÀàÊÇ Laravel ÌṩµÄÒ»¸öÜöÝÍÀà £¬·â×°Á˶ÔÊý×éµÄÖݪֲÙ×÷¡£Ê¹Óà Collection Àà¿ÉÒÔÔ½·¢Àû±ãµØ¾ÙÐÐÊý×é²Ù×÷¡£

ʹÓà Collection Àà¾ÙÐÐÈ¥ÖزÙ×÷µÄ°ì·¨ÈçÏ£º

Ê×ÏÈ £¬½¨ÉèÒ»¸ö Collection ʵÀý£º

$collection = collect($arr);

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

È»ºó £¬Ê¹Óà unique ÒªÁì¾ÙÐÐÈ¥ÖØ£º

$uniqueCollection = $collection->unique();

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

×îºó £¬¿ÉÒÔʹÓà toArray ÒªÁ콫ÜöÝÍת»»ÎªÊý×飺

$uniqueArr = $uniqueCollection->toArray();

µÇ¼ºó¸´ÖÆ

ÓëʹÓø¨Öúº¯ÊýµÄ·½·¨Ïà±È £¬Ê¹Óà Collection Àà¿ÉÒÔïÔÌ­´úÂëÈßÓà £¬Ê¹´úÂëÔ½·¢¼òÆÓÒ׶®¡£

×ܽá

±¾ÎÄÏÈÈÝÁËʹÓà Laravel ʵÏÖÒƳýÊý×éÖÐÏàֵͬµÄÒªÁ졣ʹÓà PHP ×Ô´øµÄ array_unique º¯Êý¿ÉÒÔºÜÀû±ãµØÈ¥ÖØÊý×é £¬µ«ÓпÉÄܵ¼ÖÂÊý×éϱêÖØÖõÄÎÊÌâ¡£¶øʹÓà Laravel µÄ¸¨Öúº¯Êý»ò Collection Àà¿ÉÒÔ×èÖ¹Õâ¸öÎÊÌâ £¬²¢ÇÒ¿ÉÒÔÌṩԽ·¢Àû±ãµÄ´úÂëʵÏÖ·½·¨¡£ÔÚÏÖʵ¿ª·¢ÖÐ £¬¿ÉÒÔƾ֤ÐèÇóÑ¡ÔñÊʺϵÄÒªÁìÀ´¾ÙÐÐÊý×éÈ¥ÖزÙ×÷¡£

ÒÔÉϾÍÊÇlaravel Êý×éÒƳýÏàͬµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ