10¸öÖµµÃÉî˼µÄPHPÃæÊÔÌâ

5年以前  |  阅读数:779 次  |  编程语言:PHP 

ÎÄÕÂËuÂÞÁеÄÎÊÌaËaÈ»¿´ËƼoµ¥£¬µ«ÊÇÿ¸o±³ºo¶¼º­¸ÇÁËÒ»¸o»o¼¸¸o´o¼ÒÈÝÒ׺oÊӵĻu´¡ÖªÊ¶µa£¬Ï£ÍuÄܹ»°iÖuµ½ÄaµÄÃaeÊÔºÍƽʱ¹¤×÷¡£

Q1

µÚÒ»¸oÎÊÌa¹ØÓÚÈoÀaÐÍ


    $str1 = 'yabadabadoo';
    $str2 = 'yaba';
    if (strpos($str1,$str2)) { 
      echo "/"" . $str1 . "/" contains /"" . $str2 . "/"";
    } else {
      echo "/"" . $str1 . "/" does not contain /"" . $str2 . "/"";
    }

ÕýÈ*ÔËÐеÄÊa³o½a¹u:

"yabadabadoo" does not contain "yaba"

strposÊǵ»Ø×Öu´®str2ÔÚstr1µÄλÖã¬Ã»ÓÐÕÒµ½Ôoµ»ØfalseÈ»¶øʵ¼ÊÉÏÕa´Îµ»ØÁË0¶øÔÚifÓi¾aÖÐ0Ò²±»µ±×÷false,ËuÒÔÎÒÃÇÐeÒª¶Ôfalse×oÀaÐÍÅжϣ¬ÕýÈ*µÄ´uÂeÈçÏÂ:


    $str1 = 'yabadabadoo';
    $str2 = 'yaba';
    if (strpos($str1,$str2) !== false) { 
      echo "/"" . $str1 . "/" contains /"" . $str2 . "/"";
    } else {
      echo "/"" . $str1 . "/" does not contain /"" . $str2 . "/"";
    }

ÐeҪעÒaµÄÊÇÎÒÃÇʹÓÃÁË!==£¬ÔÚphp ºÍ JSÖÐ= !Ïa¶Ô== ¸uΪÑϸñÐeÒªÒªÇoÊý¾ÝÀaÐÍÒ»Ö¡£

Q2

ÏÂÃaeµÄÊa³o½a¹u»aÊÇÔoÑu?


    $x = 5;
    echo $x; 
    echo "<br />"; 
    echo $x+++$x++; 
    echo "<br />"; 
    echo $x; 
    echo "<br />"; 
    echo $x---$x--; 
    echo "<br />"; 
    echo $x;

ʵ¼ÊÔËÐнa¹uÊÇ

5
11
7
1
5
¹ØÓÚ $x++ ºÍ $x¨CÕa¸oÎÊÌaÆaʵ*dz£ÈÝÒ×Óo¼u£¬ÎÒÃÇÖ»Ðe¼Çס$x++ʹÓÃ×i½uµÄÖµ£¬È»ºo²Å×ÔÔo¡£

ÔËËauµÄÓÅÏȼ¶£¬++ ÊÇÃ÷ÏÔ¸ßÓÚ +£¬Òo´ËÏÈÖ´ÐÐ++ ÔÙÖ´ÐÐ + ¡£¹ØÓÚÔËËauµÄÓÅÏȼ¶£¬ÓеÄʱºoÎÒÃÇÕaeµÄ¿ÉÒÔͨ¹ýÀ¨ºÅÀ´ÈÃÎÒÃǵijÌÐo¸uÈÃÈËÖ±¹ÛµÄÁ˽a£¬±Ï¾¹´uÂe²»¹aÊÇÓÃÓÚÖ´Ðеģ¬ÓеÄʱºo»oÐiÍŶӵĿɶÁÐÔÒ²ÊÇÌa¸ßЧÂʵÄÒ»ÖÖ¡£

Q3

¹ØÓÚ±aÁ¿µÄÒýÓÃ;


    $a = '1';
    $b = &$a;
    $b = "2$b";

ÇeÎÊ $a ºÍ $bµÄÖµ¸÷λ¶aÉÙ

²¿*ÖµÚһʱ¼a»aÏeµ½ $a='1¡a $b='21¡a,×Ðϸһ¿´ $b=&$a,ÕaÀi$bÊDZaÁ¿$aµÄÒýÓöø²»ÊÇÖ±½Ó ¸³Öµ¡£

Q4

ÏÂÃaeÊÇtrue»¹ÊÇfalse


    var_dump(0123 == 123);
    var_dump('0123' == 123);
    var_dump('0123' === 123);
    var_dump(0123 == 123);
    // false,PHP»aĬÈÏ°Ñ0123µ±×÷8½øÖÆÀ´´¦Ài£¬Êµ¼Êת»¯Îª10½øÖƾÍÊÇ83£¬ÏÔÈ»Õa²»ÊÇÏaµÈµÄ¡£
    var_dump('0123¡a == 123);
    // trueÕaÀiphp»a*dz£ÓÐȤµÄ½«'0123¡aת»»³ÉÒ»¸oÊý×Ö¶øÇÒĬÈÏÈ¥µoÁËÇ°ÃaeµÄ0Ò²¾ÍÊÇ123==123
    var_dump('0123¡a === 123);
    // falseºÜÏÔÈ»ÉÏÃaeµÄÎÊÌaÒѾ­Ëµ¹ýÁËÊý×ÖºÍ×Ö*u´®ÀaÐͲ»Ò»Ö¡£

Q5

ÏÂÃaeµÄ´uÂeÓÐʲôÎÊÌaÂð?Êa³o»aÊÇʲô£¬ÔoÑuÐÞ¸´Ëu


    $referenceTable = array();
    $referenceTable['val1'] = array(1, 2);
    $referenceTable['val2'] = 3;
    $referenceTable['val3'] = array(4, 5);

    $testArray = array();

    $testArray = array_merge($testArray, $referenceTable['val1']);
    var_dump($testArray); 
    $testArray = array_merge($testArray, $referenceTable['val2']);
    var_dump($testArray); 
    $testArray = array_merge($testArray, $referenceTable['val3']);
    var_dump($testArray);

ʵ¼ÊÊa³oÈçÏ£º


    array(2) { [0]=> int(1) [1]=> int(2) }
    NULL
    NULL

ÔËÐеÄʱºoÄa»oÐi»¹ÄÜ¿´µ½ÏÂÃaeµÄ¾¯¸ae

Warning: array_merge(): Argument #2 is not an array
Warning: array_merge(): Argument #1 is not an array

array_mergeÐeÒª´«ÈeµÄ²ÎÊý¶¼ÊÇÊý×e£¬Èç¹u²»ÊÇ£¬Ôo»a*µ»Ønull¡£ Äa¿ÉÒÔÕaÑuÐÞ¸Ä


    $testArray = array_merge($testArray, (array)$referenceTable['val1']);
    var_dump($testArray);
    $testArray = array_merge($testArray, (array)$referenceTable['val2']);
    var_dump($testArray);
    $testArray = array_merge($testArray, (array)$referenceTable['val3']);
    var_dump($testArray);

Q6

$xÓ¦¸ÃÊÇÊa³oʲô?


    $x = true and false;
    var_dump($x);

²¿Öͬѧ»oÐi»aµÚһʱ¼aÏeµ½false,ʵ¼ÊÉÏÕaÀiÒÀ¾ÉÊÇÇ¿µ÷ÔËËauµÄÓÅÏȼ¶£¬= »a±È and¼¶±ð¸ßµa£¬Òo´ËµÈͬÏÂÃaeµÄ´uÂe


    $x = true;
    true and false

´ð°¸ÏÔ¶øÒ×¼u¡£

Q7

¾­¹ýÏÂÃaeµÄÔËËa $xµÄÖµÓ¦¸ÃÊǶaÉÙ?

$x = 3 + "15%" + "$25"

´ð°¸ÊÇ18£¬PHPÊÇ»a¸u¾ÝÉÏÏÂÎÄʵÏÖÀaÐ͵Ä×Ô¶¯×ª»»

ÉÏÃaeµÄ´uÂeÎÒÃÇ¿ÉÒÔÕaÑuÀi½a£¬Èç¹uÎÒÃÇÔÚÓe×Öu´®½øÐÐÊýѧÔËËa£¬Êµ¼Êphp»a¾¡¿ÉÄܽ«×Öu´®ÖеÄÊý×e½øÐÐת»»£¬Èç¹uÊÇÊý×Ö¿ªÍµÄ»°Ôoת»»³É¸ÄÊý×Ö±ÈÈ硱15%¡±»a±a³É15,Èç¹u²»ÊÇÊý×Ö¿ªÍÔo»a±a³É0; ÉÏÃaeµÄÔËËaÀaËÆÏÂÃae £º

$x = 3 + 15 + 0

Q8

ÔËÐÐÏÂÃaeµÄ´uÂe£¬$text µÄÖµÊǶaÉÙ?strlen($text)ÓÖ»a*µ»Øʲô½a¹u?


    $text = 'John ';
    $text[10] = 'Doe';

ÉÏÃae´uÂeÖ´ÐÐÍe±Ïºo $text = ¡°John D¡±(JohnºoÃae»aÓÐÁ¬ÐøµÄ5¸o¿Õ¸ñ) strlen($text)»a*µ»Ø11

$text[10] = ¡°Doe¡±¸øij¸o×Öu´®¾ßÌaµÄij¸oλÖþßÌa×Öuʱºo£¬Êµ¼ÊÖ»»a°ÑD¸³¸ø$text. ËaÈ»$text²Å¿ªÊ¼Ö»ÓÐ5¸o×Ô¸º³¤¶È£¬µ«ÊÇphp»aĬÈÏÌi³a¿Õ¸ñ¡£ÕaºÍ±ðµÄÓiÑÔÓÐÐ(C)²i±ð¡£

Q9

ÏÂÃaeµÄÊa³o½a¹u»aÊÇʲô


    $v = 1;
    $m = 2;
    $l = 3;

    if( $l > $m > $v){ 
      echo "yes";
    }else{
      echo "no";
    }

ʵ¼ÊµÄÊa³oÊÇ¡±no¡±,Ö»Òª×Ðϸ*ÖÎo¾Í²»Äѵóo

$l>$m »aת»»³É1 £¬ÔoÕa¸oʱºoÔÙºÍ$m±È½Ï¡£

Q10

Ö´ÐÐÏÂÃae´uÂe$x»a±a³ÉʲôֵÄØ?


    $x = NULL;

    if ('0xFF' == 255) { 
      $x = (int)'0xFF';
    }

ʵ¼ÊµÄÔËÐнa¹uÊÇ$x=0¶ø²»ÊÇ255.

Ê×ÏÈ'oxFF' == 255ÎÒÃǺÃÅжϣ¬»a½øÐÐת»»½«16½øÖÆÊý×Öת»»³É10½øÖÆÊý×Ö£¬0xff -> 255.

PHPʹÓÃis_numeric_string ÅжÏ×Öu´®ÊÇñ°uº¬Ê®Áu½øÖÆÊý×ÖÈ»ºo½øÐÐת»»¡£

µ«ÊÇ$x = (int)'0xFF';ÊÇñÒ²»a±a³É255ÄØ?ÏÔÈ»²»ÊÇ£¬½«Ò»¸o×Öu´®½øÐÐÇ¿ÖÆÀaÐÍת»»Êµ¼ÊÉÏÓõÄÊÇconvert_to_long,Ëuʵ¼ÊÉÏÊǽ«×Öu´®´Ó×oÏoÓÒ½øÐÐת»»£¬Óoµ½ÇÊý×Ö×Ö*uÔoÍ£Ö¹¡£Òo´Ë0xFFµ½x¾ÍÍ£Ö¹ÁË¡£ËuÒÔ$x=0

ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例