×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravelÔõôÅжϿÕÖµ

ÔÚlaravel¿ª·¢ÖÐ £¬ÎÒÃǾ­³£ÐèÒªÅжÏij¸ö±äÁ¿ÊÇ·ñΪ¿Õ¡£ÔÚphpÖÐ £¬ÎÒÃÇͨ³£Ê¹ÓÃempty()ºÍisset()º¯ÊýÀ´ÅжÏÊÇ·ñΪ¿Õ £¬µ«ÔÚlaravelÖÐ £¬ÓиüÀû±ãµÄÒªÁìÀ´´¦Àí¿ÕÖµÅжÏ¡£ÏÂÃ潫ÏÈÈÝһЩlaravelÅжϿÕÖµµÄ³£ÓÃÒªÁì¡£

ʹÓÃnull

ÔÚLaravelÖÐ £¬¿ÉÒÔʹÓÃnullÀ´ÌåÏÖÒ»¸ö±äÁ¿Îª¿Õ¡£ÈôÊDZäÁ¿µÄֵΪnull £¬ËµÃ÷ËüûÓб»¸³Öµ»òÕß±»ÏÔʽµØ¸³ÖµÎªnull¡£

ÀýÈç £¬ÈôÊÇÒªÅжÏÒ»¸ö±äÁ¿ÊÇ·ñΪ¿Õ £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if ($variable === null) {
    // ±äÁ¿Îª¿Õ
}

µÇ¼ºó¸´ÖÆ

ʹÓÃempty()

ËäÈ»ÔÚPHPÖÐempty()º¯ÊýµÄÌåÏÖ²¢²»ÎȹÌ £¬µ«ÔÚLaravelÖÐËü±»ÖØнç˵Ϊһ¸ö¸üÇå¾²¡¢¸ü¿É¿¿µÄº¯Êý¡£empty()º¯Êý¿ÉÒÔÓÃÀ´ÅжϱäÁ¿ÊÇ·ñΪ¿Õ¡£

ÀýÈç £¬¼ÙÉèÄãÏëÅжÏÒ»¸ö×Ö·û´®ÊÇ·ñΪ¿Õ £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if (empty($string)) {
    // ×Ö·û´®Îª¿Õ
}

µÇ¼ºó¸´ÖÆ

empty()º¯Êý²»µ«¿ÉÒÔÅжÏ×Ö·û´®ÊÇ·ñΪ¿Õ £¬»¹¿ÉÒÔÅжÏÆäËûÀàÐ͵ıäÁ¿¡£

ʹÓÃis_null()

is_null()º¯ÊýÊÇÒ»¸öPHPº¯Êý £¬µ«ÔÚLaravelÖÐÒ²¿ÉÒÔʹÓ᣸ú¯ÊýÓÃÓÚÅжÏÒ»¸ö±äÁ¿ÊÇ·ñΪnull¡£

ÀýÈç £¬ÈôÊÇÒªÅжÏÒ»¸ö±äÁ¿ÊÇ·ñΪnull £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if (is_null($variable)) {
    // ±äÁ¿Îª¿Õ
}

µÇ¼ºó¸´ÖÆ

ʹÓÃ$variable

ÔÚLaravelÖÐ £¬Ö±½ÓʹÓñäÁ¿Ãû¿ÉÒÔÅжϱäÁ¿ÊÇ·ñΪ¿Õ¡£ÈôÊÇÒ»¸ö±äÁ¿²»±£´æ»òÕß±»¸³ÖµÎªnull £¬Õâ¸ö±äÁ¿»á±»ÒÔΪÊǿյġ£

ÀýÈç £¬ÈôÊÇÒªÅжÏÒ»¸ö±äÁ¿ÊÇ·ñΪ¿Õ £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if (!$variable) {
    // ±äÁ¿Îª¿Õ
}

µÇ¼ºó¸´ÖÆ

×¢ÖØ £¬ÕâÖÖÒªÁìÖ»ÊÊÓÃÓÚÅжϱäÁ¿ÊÇ·ñΪ¿Õ £¬²»¿ÉÓÃÓÚÅжϱäÁ¿ÊÇ·ñ±£´æ¡£

ʹÓÃis_null()ºÍempty()

ÔÚijЩÇéÐÎÏ £¬Í¨¹ý×éºÏʹÓÃis_null()ºÍempty()º¯Êý¿ÉÒÔ¸ü׼ȷµØÅжϱäÁ¿ÊÇ·ñΪ¿Õ¡£ÀýÈç £¬ÈôÊÇÒªÅжÏÒ»¸öÊý×éÊÇ·ñΪ¿Õ £¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺

if (is_null($array) || empty($array)) {
    // Êý×éΪ¿Õ
}

µÇ¼ºó¸´ÖÆ

ÕâÖÖÒªÁì¿ÉÒÔ×èÖ¹¿ÕÊý×éºÍnullÊý×éÖ®¼äµÄ»ìÏý¡£

×ܽá

ÒÔÉÏÊÇLaravelÖеÄһЩ³£ÓÃÒªÁìÀ´ÅжϿÕÖµ¡£ËäÈ»ÔÚPHPÖÐÒ²ÓÐÀàËƵĺ¯Êý £¬¿ÉÊÇÔÚLaravelÖÐ £¬ÕâЩº¯Êý±»ÖØнç˵ºÍÓÅ»¯ £¬Ê¹µÃÅжÏÔ½·¢Àû±ã¡¢Çå¾²¡¢¿É¿¿¡£ÔÚÏÖʵ¿ª·¢ÖÐ £¬²»¹ÜʲôÇéÐÎ £¬ÎÒÃǶ¼ÒªÑø³ÉÅжϱäÁ¿ÊÇ·ñΪ¿ÕµÄºÃÏ°¹ß¡£Ö»ÓÐÕâÑù £¬ÎÒÃǵijÌÐò²Å»ªÔ½·¢½áʵ¡¢ÎȹÌ¡£

ÒÔÉϾÍÊÇlaravelÔõôÅжϿÕÖµµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ