×ðÁú¿­Ê±

laravelÊý×éÊÇ·ñ°üÀ¨Ï±ê

ÔÚ laravel ÖÐ £¬Êý×éÊǺܳ£¼ûµÄÊý¾ÝÀàÐÍ £¬Ðí¶àÇéÐÎÏÂÎÒÃÇÐèÒªÅжÏÒ»¸öÊý×éÊÇ·ñ°üÀ¨Ä³¸öϱê¡£Õâ¸öÎÊÌâ¿´ËƼòÆÓ £¬µ«ÈôÊDz»Ïàʶ laravel ÖеÄÏêϸʵÏÖ £¬¾ÍºÜÈÝÒ׳ö´í¡£±¾ÎĽ«ÏÈÈÝ laravel ÖÐÔõÑùÅжÏÊý×éÊÇ·ñ°üÀ¨Ï±ê¡£

Ê×ÏÈ £¬ÎÒÃÇÀ´¿´Ò»Ï PHP ÖеÄÊý×éÅжϷ½·¨¡£ÔÚ PHP ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓà isset() »ò array_key_exists() º¯ÊýÀ´ÅжÏÊý×éÊÇ·ñ°üÀ¨Ä³¸öϱê¡£ËüÃǵÄʹÓ÷½·¨ÈçÏÂËùʾ£º

$array = ['name' => 'John', 'age' => 30];

// ʹÓÃisset()º¯ÊýÅжÏÊý×éÊÇ·ñ°üÀ¨Ï±ê
if (isset($array['name'])) {
    echo 'Name is set.';
} else {
    echo 'Name is not set.';
}

// ʹÓÃarray_key_exists()º¯ÊýÅжÏÊý×éÊÇ·ñ°üÀ¨Ï±ê
if (array_key_exists('age', $array)) {
    echo 'Age is set.';
} else {
    echo 'Age is not set.';
}

µÇ¼ºó¸´ÖÆ

ÕâÁ½¸öº¯Êý¶¼ÊÇ PHP Öг£¼ûµÄ²Ù×÷Êý×éµÄ·½·¨¡£È»¶ø £¬ÔÚ Laravel ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓøüΪ¼òÆÓµÄÓï·¨À´ÅжÏÊý×éÊÇ·ñ°üÀ¨Ï±ê¡£

ÔÚ Laravel ÖÐ £¬¿ÉÒÔʹÓà isset() ¾ÙÐÐÊý×éϱêÅÐ¶Ï £¬¿ÉÊÇÔ½·¢ÍƼöʹÓà array_key_exists() º¯Êý¡£ array_key_exists() º¯Êý¿ÉÒÔ½ÓÊÜÁ½¸ö²ÎÊý £¬µÚÒ»¸ö²ÎÊýÊÇÐèÒªÅжϵÄϱêÃû³Æ £¬µÚ¶þ¸ö²ÎÊýÔòÊÇÐèÒª¾ÙÐÐÅжϵÄÊý×é¡£ÆäʹÓ÷½·¨ÈçÏÂËùʾ£º

$array = ['name' => 'John', 'age' => 30];

if (array_key_exists('name', $array)) {
    echo 'Name is set.';
} else {
    echo 'Name is not set.';
}

if (array_key_exists('email', $array)) {
    echo 'Email is set.';
} else {
    echo 'Email is not set.';
}

µÇ¼ºó¸´ÖÆ

ƾ֤ÉÏÊö´úÂë £¬ÈôÊÇ $array Êý×é°üÀ¨ name ϱê £¬ÔòÊä³ö¡°Name is set.¡± £¬²»È»Êä³ö¡°Name is not set.¡±¡£Í¬ÑùµØ £¬ÈôÊÇ $array Êý×é²»°üÀ¨ email ϱê £¬ÔòÊä³ö¡°Email is not set.¡±¡£

ÐèҪעÖصÄÊÇ £¬Ê¹Óà array_key_exists() º¯ÊýÐèҪעÖØϱêµÄÀàÐÍ¡£ÈôÊÇϱêÊÇÒ»¸ö¿ÕÖµ null £¬ÄÇô¸Ãº¯Êý½«·µ»Ø false ²¢±¬·¢Ò»¸ö E_WARNING ¼¶±ðµÄ¹ýʧ¡£ÁíÍâ £¬ÈôÊÇÐèÒªÅжϵÄϱêÊÇÊý×Ö £¬ÄÇôÔÚʹÓà isset() º¯ÊýʱµÄÅжÏÌõ¼þ»áÊ®·ÖµÄÑÏ¿á £¬ÐèҪͬʱÅжÏϱ걣´æ²¢ÇÒÆä¶ÔÓ¦µÄÖµ²»ÊÇ null¡£

×îºó £¬ÐèÒªÌáÐѸ÷È˵ÄÊÇ £¬ÔÚʹÓÃÊý×éʱӦ¸Ã¾¡¿ÉÄÜ×èÖ¹·ºÆðδ½ç˵µÄϱê¡£ÈôÊÇÊý×éϱêʹÓò»µ± £¬½«»áµ¼Ö³ÌÐòÔËÐÐʱ·ºÆð¹ýʧ £¬ÉõÖÁ¿ÉÄÜÒýÆðÇå¾²Òþ»¼¡£Òò´Ë £¬×¼È·µÄÒªÁìÊÇÔÚʹÓÃÊý×éÇ° £¬Ö»¹ÜÈ·±£Êý×éϱ궼ÊÇ¿ÉÓõÄ¡£

ÔÚ±¾ÎÄÖÐÎÒÃÇÏÈÈÝÁË Laravel ÖÐÊý×éÅжÏϱêÊÇ·ñ±£´æµÄÒªÁì £¬ÆäÖÐ array_key_exists() ÊÇ×î³£ÓõÄÒªÁì £¬²¢ÇÒ±È isset() Ô½·¢ÎÞаºÍÇå¾² £¬Äܹ»¸üºÃµÄ˳Ӧ Laravel µÄ´úÂë¹æ·¶ºÍ³ÌÐòÉè¼ÆÏ°¹ß¡£ÎÒÃÇÏ£Íû¶ÁÕßÃÇÔÚ¿ª·¢ Laravel Ó¦ÓóÌÐòʱʹÓÃÕâÖÖÒªÁìÀ´ÅжÏÊý×éϱê¡£

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

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