{"id":2570,"date":"2013-03-15T19:03:53","date_gmt":"2013-03-15T11:03:53","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=2570"},"modified":"2013-03-15T19:49:41","modified_gmt":"2013-03-15T11:49:41","slug":"%e6%9c%80%e8%bf%91%e9%81%87%e5%88%b0%e7%9a%84%e4%b8%80%e4%ba%9b%e9%9d%a2%e8%af%95%e9%a2%98","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/2570.html","title":{"rendered":"\u6700\u8fd1\u9047\u5230\u7684\u4e00\u4e9b\u9762\u8bd5\u9898"},"content":{"rendered":"<p>\u4ee5\u4e0b\u662f\u6211\u6700\u8fd1\u9762\u8bd5\u9047\u5230\u7684\u4e00\u4e9b\u9762\u8bd5\u9898\u76ee\uff0c\u662f\u6211\u505a\u5b8c\u540e\u7528\u624b\u673a\u62cd\u4e0b\u56de\u6765\u6574\u7406\u51fa\u6765\u7684\u3002\u7edd\u5927\u90e8\u5206\u9898\u76ee\u90fd\u662f\u76f4\u63a5\u5728\u7f51\u4e0a\u53ef\u4ee5\u5f88\u5bb9\u6613\u627e\u5230\u539f\u9898\u3002<\/p>\n<p>1\u3001\u5199\u4e00\u4e2a\u6392\u5e8f\u7b97\u6cd5\uff0c\u53ef\u4ee5\u662f\u5192\u6ce1\u6392\u5e8f\u6216\u8005\u662f\u5feb\u901f\u6392\u5e8f\uff0c\u5047\u8bbe\u6392\u5e8f\u5bf9\u8c61\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/\u5192\u6ce1\u6392\u5e8f\uff08\u6570\u7ec4\u6392\u5e8f\uff09\r\nfunction bubble_sort($array) {\r\n  $count = count($array);\r\n  if ($count &lt;= 0) return false;\r\n  for($i=0; $i&lt;$count; $i++){\r\n         for($j=$count-1; $j&gt;$i; $j--){\r\n           if ($array&#x5B;$j] &lt; $array&#x5B;$j-1]){\r\n              $tmp = $array&#x5B;$j];\r\n              $array&#x5B;$j] = $array&#x5B;$j-1];\r\n              $array&#x5B;$j-1] = $tmp;\r\n           }\r\n         }\r\n  }\r\n  return $array;\r\n}\r\n\r\n\/\/\u5feb\u901f\u6392\u5e8f\uff08\u6570\u7ec4\u6392\u5e8f\uff09\r\nfunction quicksort($array) {\r\n  if (count($array) &lt;= 1) return $array;\r\n  $key = $array&#x5B;0];\r\n  $left_arr = array();\r\n  $right_arr = array();\r\n  for ($i=1; $i&lt;count($array); $i++){\r\n         if ($array&#x5B;$i] &lt;= $key)  $left_arr&#x5B;] = $array&#x5B;$i];\r\n         else $right_arr&#x5B;] = $array&#x5B;$i];\r\n  }\r\n  $left_arr = quicksort($left_arr);\r\n  $right_arr = quicksort($right_arr);\r\n  return array_merge($left_arr, array($key), $right_arr);\r\n}\r\n<\/pre>\n<p>2\u3001\u5b9e\u73b0\u4e00\u4e2a\u5b57\u7b26\u4e32\u622a\u53d6\u7684\u51fd\u6570\uff0c\u7c7b\u4f3c\u4e8esubstr\uff0c\u5fc5\u987b\u80fd\u591f\u622a\u53d6\u4e2d\u6587\u8fd9\u79cd\u591a\u5b57\u8282\u5b57\u7b26\u4e32\uff08\u5047\u8bbe\u6bcf\u4e2a\u4e2d\u6587\u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u666e\u901a\u7684\u6570\u5b57\u3001\u5b57\u53f7\u3001\u5b57\u6bcd\u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\uff0cGB2312\u4e2d\u6587\u5b57\u7b26\u9ad8\u4f4d\u8303\u56f4\u662f0x81-0xFE\uff09\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/**\r\n* \u4e2d\u6587\u5b57\u7b26\u4e32\u622a\u53d6\uff083\uff09\uff08\u652f\u6301GB2312\/GBK\/UTF-8\/BIG5\uff09\r\n* @param string $str \u8981\u622a\u53d6\u7684\u5b57\u4e32\r\n* @param int $start \u622a\u53d6\u8d77\u59cb\u4f4d\u7f6e\r\n* @param int $length \u622a\u53d6\u957f\u5ea6\r\n* @param string $charset \u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u96c6\uff0c\u5305\u62ec\u6709 utf-8|gb2312|gbk|big5 \u7f16\u7801\r\n* @param bool $suffix \u662f\u5426\u52a0\u5c3e\u7f00\r\n* @return string \u8fd4\u56de\u63a5\u7eed\u5b57\u7b26\u4e32\u7684\u7ed3\u679c\r\n*\/\r\nfunction CSubstr($str, $start=0, $length, $charset=&quot;gbk&quot;, $suffix=false){\r\n  if(function_exists(&quot;mb_substr&quot;)){\r\n    return mb_substr($str, $start, $length, $charset);\r\n  }\r\n  $re&#x5B;'utf-8'] = &quot;\/&#x5B;\\x01-\\x7f]|&#x5B;\\xc2-\\xdf]&#x5B;\\x80-\\xbf]|&#x5B;\\xe0-\\xef]&#x5B;\\x80-\\xbf]{2}|&#x5B;\\xf0-\\xff]&#x5B;\\x80-\\xbf]{3}\/&quot;;\r\n  $re&#x5B;'gb2312'] = &quot;\/&#x5B;\\x01-\\x7f]|&#x5B;\\xb0-\\xf7]&#x5B;\\xa0-\\xfe]\/&quot;;\r\n  $re&#x5B;'gbk'] = &quot;\/&#x5B;\\x01-\\x7f]|&#x5B;\\x81-\\xfe]&#x5B;\\x40-\\xfe]\/&quot;;\r\n  $re&#x5B;'big5'] = &quot;\/&#x5B;\\x01-\\x7f]|&#x5B;\\x81-\\xfe](&#x5B;\\x40-\\x7e]|\\xa1-\\xfe])\/&quot;;\r\n  preg_match_all($re&#x5B;$charset], $str, $match);\r\n  $slice = join(&quot;&quot;, array_slice($match&#x5B;0], $start, $length));\r\n  if($suffix) {\r\n    return $slice .&quot;\u2026&quot;;\r\n  }\r\n  return $slice;\r\n}\r\n<\/pre>\n<p>3\u3001\u5199\u4e00\u4e2a\u904d\u5386\u6307\u5b9a\u76ee\u5f55\u4e0b\u6240\u6709\u5b50\u76ee\u5f55\u548c\u5b50\u6587\u4ef6\u7684\u51fd\u6570\uff08\u63d0\u793a\uff1a\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u7684\u65b9\u6cd5\uff09\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/**\r\n* \u9012\u5f52\u7684\u904d\u5386\u4e00\u4e2a\u6307\u5b9a\u76ee\u5f55\r\n*\/\r\nfunction dir_all ( $path ) {\r\n  $handler = opendir($path);\r\n  while (false !== ($tmp = readdir($handler))) {\r\n    if(is_dir( &quot;$path\/$tmp&quot; )) {\r\n      if ($tmp==&quot;.&quot; | $tmp==&quot;..&quot;) continue;\r\n      echo $tmp.&quot;&lt;br&gt;\\n&quot;;\r\n      dir_all (&quot;$path\/$tmp&quot;);\r\n    } else {\r\n      echo $tmp .&quot;&lt;br&gt;\\n&quot;;\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>4\u3001\u5199\u51fa\u5339\u914d\u90ae\u7bb1\u5730\u5740\u548cURL\u7684\u4e24\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7c7b\u4f3c\u4e0b\u9762\u7684\uff1a<\/p>\n<p>\u90ae\u7bb1\u5730\u5740\uff1a user_name.first@example.com.cn<br \/>\nURL\u5730\u5740\uff1ahttp:\/\/www.example.com.cn\/user_profile.php?uid=100<br \/>\n\uff08\u63d0\u793a\uff1a\u4f7f\u7528\u6807\u51c6\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5c31\u662fphp\u4e2dpreg_*\u7c7b\u7684\u6b63\u5219\u5904\u7406\u51fd\u6570\u80fd\u591f\u89e3\u6790\u7684\u6b63\u5219\uff09<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u90ae\u7bb1\uff1a\/\\w+(&#x5B;-+.]\\w+)*@\\w+(&#x5B;-.]\\w+)*\\.\\w+(&#x5B;-.]\\w+)*\/\r\nURL\uff1a\/^http:\\\/\\\/&#x5B;\\w]+\\.&#x5B;\\w]+&#x5B;\\S]*\/\r\n<\/pre>\n<p>5\u3001\u5199\u51fa\u4e09\u79cd\u4ee5\u4e0aMySQL\u6570\u636e\u5e93\u7684\u5b58\u50a8\u5f15\u64ce\u7684\u540d\u79f0\u3002\u4e0d\u540d\u5206\u5927\u5c0f\u5199<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nMyISAM\u3001InnoDB\u3001MERGE\u3001MEMORY(HEAP)\u3001BDB(BerkeleyDB)\u3001EXAMPLE\u3001FEDERATED\u3001ARCHIVE\u3001CSV\u3001BLACKHOLE\u3002\r\nMyISAM\u7ba1\u7406\u975e\u4e8b\u52a1\u8868\u3002\u5b83\u63d0\u4f9b\u9ad8\u901f\u5b58\u50a8\u548c\u68c0\u7d22\uff0c\u4ee5\u53ca\u5168\u6587\u641c\u7d22\u80fd\u529b\u3002\r\nMEMORY\u5b58\u50a8\u5f15\u64ce\u63d0\u4f9b\u201c\u5185\u5b58\u4e2d\u201d\u8868\u3002\r\nInnoDB\u548cBDB\u5b58\u50a8\u5f15\u64ce\u63d0\u4f9b\u4e8b\u52a1\u5b89\u5168\u8868\u3002\r\nNDB Cluster\u662f\u88abMySQL Cluster\u7528\u6765\u5b9e\u73b0\u5206\u5272\u5230\u591a\u53f0\u8ba1\u7b97\u673a\u4e0a\u7684\u8868\u7684\u5b58\u50a8\u5f15\u64ce\u3002\r\n<\/pre>\n<p>6\u3001\u8bf4\u51fa\u4f60\u6240\u77e5\u9053\u7684\u4e09\u79cd\u4ee5\u4e0a\u5f00\u6e90\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nMYSQL  PostgreSQL  Firebird  Berkeley  DBSQLite  PostgreSQL\r\n<\/pre>\n<p>7\u3001MySQL\u6570\u636e\u5e93\u4e2d\u7684\u5b57\u7b26\u7c7b\u578bvarchar\u548cchar\u7684\u4e3b\u8981\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u54ea\u79cd\u5b57\u7b26\u67e5\u8be2\u6548\u7387\u8981\u9ad8\uff1f\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nvarchar\u662f\u53ef\u53d8\u957f\u5ea6\uff0c\u800cchar\u4e3a\u56fa\u5b9a\u957f\u5ea6\u3002\r\nchar\u6548\u7387\u8981\u9ad8\u3002\r\n<\/pre>\n<p>8\u3001MySQL\u6570\u636e\u5e93\u57fa\u672c\u7684\u4e09\u4e2a\u4f18\u5316\u6cd5\u5219\u662f\u4ec0\u4e48\uff1f\uff08\u63d0\u793a\uff1a\u4ece\u670d\u52a1\u914d\u7f6e\u3001\u5e94\u7528\u3001\u5f00\u53d1\u4e09\u4e2a\u89d2\u5ea6\u8003\u8651\uff09\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u7cfb\u7edf\u670d\u52a1\u4f18\u5316\uff0c\u628amysql\u7684key_buffer\u3001cache_buffer\u3001query_buffer\u7b49\u589e\u52a0\u5bb9\u91cf\r\n\u7ed9\u6240\u6709\u7ecf\u5e38\u67e5\u8be2\u7684\u5b57\u6bb5\u9002\u5f53\u589e\u52a0\u76f8\u5e94\u7684\u7d22\u5f15\r\n\u4f18\u5316sql\u8bed\u53e5\uff0c\u51cf\u5c11Distinct\uff0cGroup\uff0cJoin\u7b49\u8bed\u53e5\u7684\u64cd\u4f5c\r\n<\/pre>\n<p>9\u3001\u8bf7\u4f7f\u7528JavaScript\u5199\u51fa\u4e09\u79cd\u4ea7\u751f\u4e00\u4e2aImage\u6807\u7b7e\u7684\u65b9\u6cd5\u3002\uff08\u63d0\u793a\uff1a\u4ece\u65b9\u6cd5\u3001\u5bf9\u8c61\u3001HTML\u89d2\u5ea6\u8003\u8651\uff09<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar img = new Image();\r\nvar img = document.createElementById('image');\r\nimg.innerHTML = '&lt;img src=xxx.jpg \/&gt;';\r\n<\/pre>\n<p>10\u3001\u8bf7\u4f7f\u7528CSS\u6837\u5f0f\uff0c\u63cf\u8ff0\u4e24\u79cd\u65b9\u6cd5\u5728\u5f53\u524d\u5217\u4e2d\u53ea\u663e\u793a\u4e00\u4e2adiv\u5bf9\u8c61\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div style='width:199999px;'&gt;&lt;\/div&gt;\r\n&lt;div style='clear:both;'&gt;&lt;\/div&gt;\r\n<\/pre>\n<p>11\u3001\u8bf7\u63cf\u8ff0\u4e24\u70b9\u4ee5\u4e0aXHTML\u548cHTML\u6700\u663e\u8457\u7684\u533a\u522b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n(1)XHTML\u5fc5\u987b\u5f3a\u5236\u6307\u5b9a\u6587\u6863\u7c7b\u578bDocType\uff0cHTML\u4e0d\u9700\u8981\r\n(2)XHTML\u6240\u6709\u6807\u7b7e\u5fc5\u987b\u95ed\u5408\uff0cHTML\u6bd4\u8f83\u968f\u610f\r\n<\/pre>\n<p>12\u3001\u8bf4\u51fa\u4e94\u79cd\u4ee5\u4e0a\u4f60\u4f7f\u7528\u8fc7\u7684php\u6269\u5c55\u7684\u540d\u79f0\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nMB_String  Curl  GD  socket Mysql PDO mongo gearman oauth apc\r\n<\/pre>\n<p>13\u3001\u5199\u51fa\u4e09\u79cd\u4ee5\u4e0a\u76ee\u524dphp\u6d41\u884c\u7684MVC\u6846\u67b6\u540d\u79f0\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nCodeIgniter  FleaPHP\u3001Zend Framework\u3001CakePHP\u3001Symfony\u3001Plite\u3001php.MVC\u3001PHP on Trax\u3001Smarty \u7b49\u7b49\r\n<\/pre>\n<p>14\u3001\u5199\u51fa\u5341\u4e94\u4e2a\u4ee5\u4e0a\u4f60\u6240\u77e5\u9053\u7684\u5e38\u7528Linux\u547d\u4ee4\u548c\u5b83\u7684\u529f\u80fd\u3002<\/p>\n<p>15\u3001\u8bf4\u8bf4Linux\u4e0b\u7684find\u547d\u4ee4\u548cgrep\u547d\u4ee4\u7684\u533a\u522b\u3002<\/p>\n<p>16\u3001\u8bf7\u7b80\u5355\u7684\u63cf\u8ff0Memcache\u7f13\u5b58\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<p>17\u3001\u8bf7\u5927\u81f4\u7684\u63cf\u8ff0\u4e00\u4e0bSession\u7684\u5de5\u4f5c\u539f\u7406\u3002\uff08\u63d0\u793a\uff1a\u4e0ecookie\u6709\u76f8\u5e94\u7684\u5173\u7cfb\uff09<\/p>\n<p>18\u3001\u4f60\u7528\u4ec0\u4e48\u65b9\u6cd5\u68c0\u67e5php\u811a\u672c\u7684\u6267\u884c\u6548\u7387\uff08\u901a\u5e38\u662f\u811a\u672c\u6267\u884c\u65f6\u95f4\uff09\u548cmysql\u67e5\u8be2\u6548\u7387\uff08\u901a\u5e38\u662f\u6570\u636e \u5e93Query\u65f6\u95f4\uff09\uff0c\u5e76\u5b9a\u4f4d\u548c\u5206\u6790\u811a\u672c\u6267\u884c\u548c\u6570\u636e\u5e93\u67e5\u8be2\u7684\u74f6\u9888\u3002<\/p>\n<p>19\u3001\u5047\u8bbe\u7ed9\u4f60\u4e94\u53f0\u670d\u52a1\u5668\uff0c\u8bf7\u5927\u81f4\u7684\u63cf\u8ff0\u4e00\u4e0b\uff0c\u5982\u4f55\u4f7f\u7528\u4f60\u6240\u719f\u6089\u7684\u5f00\u6e90\u8f6f\u4ef6\uff0c\u642d\u5efa\u65e5PV 300\u4e07\u5de6\u53f3\u7684\u4e2d\u578b\u7f51\u7ad9\u3002<\/p>\n<p>=========================================================<\/p>\n<p>1\u3001\u4f60\u4f7f\u7528\u8fc7\u7684php\u63d2\u4ef6\u3001\u6846\u67b6\uff1f<\/p>\n<p>2\u3001\u5982\u4f55\u89e3\u51b3jquery ajax\u7684\u8de8\u57df\u95ee\u9898\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\njsonp\r\n<\/pre>\n<p>3\u3001mysql_fetch_row()\u548cmysql_fetch_array()\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u8fd9\u4e24\u4e2a\u51fd\u6570\uff0c\u8fd4\u56de\u7684\u90fd\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u533a\u522b\u5c31\u662f\u7b2c\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u7684\u6570\u7ec4\u662f\u53ea\u5305\u542b\u503c\uff0c\u6211\u4eec\u53ea\u80fd$row&#x5B;0],$row&#x5B;1],\u8fd9\u6837\u4ee5\u6570\u7ec4\u4e0b\u6807\u6765\u8bfb\u53d6\u6570\u636e\uff0c\r\n\u800cMySQL_fetch_array()\u8fd4\u56de\u7684\u6570\u7ec4\u65e2\u5305\u542b\u7b2c\u4e00\u79cd\uff0c\u4e5f\u5305\u542b\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u8bfb\u53d6\u6570\u636e:\r\n$row&#x5B;'username'], $row&#x5B;'passwd']\r\n<\/pre>\n<p>4\u3001\u5982\u4f55\u4f7f\u7528php\u83b7\u53d6\u4e00\u4e2aurl\u7684html\u5185\u5bb9\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u7528curl\u6269\u5c55\uff0c\u6216 file_get_contents($url)\r\n<\/pre>\n<p>5\u3001$uptime = &#8216;2013-01-06 08:12:33&#8217;\uff0c\u5199\u51faphp\u8ba1\u7b97$uptime\u4e09\u5929\u540e\u65b9\u6cd5\uff1f<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$newt = strtotime('+3 days', strtotime('2013-01-06 08:12:33'));\r\necho date('Y-m-d H:i:s', $newt);\r\n<\/pre>\n<p>6\u3001php\u5982\u4f55\u5c06\u6570\u7ec4 array(&#8216;b&#8217;, &#8216;a&#8217;, &#8216;c&#8217;)\u8f6c\u53d8\u6210array([1]=&gt;&#8217;a&#8217;,[0]=&gt;&#8217;b&#8217;,[2]=&gt;&#8217;c&#8217;)\uff1f<\/p>\n<p>7\u3001preg_match(&#8220;\/^(http:\\\/\\\/)?([^\\\/]+)\/i&#8221;, &#8220;http:\/\/www.php.net\/index.html&#8221;, $matches); echo $matches[0];<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhttp:\/\/www.php.net\r\n<\/pre>\n<p>8\u3001\u6267\u884c\u5c06\u8f93\u51fa\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n2\r\n<\/pre>\n<p>9\u3001linux\u7684\u8fdc\u7a0b\u62f7\u8d1d\u547d\u4ee4\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nscp\r\n<\/pre>\n<p>10\u3001linux\u4fee\u6539\u6587\u4ef6filename\u53ca\u5176\u5b50\u76ee\u5f55\u7684\u62e5\u6709\u8005\u4e3ausername<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nchown filename username\r\n<\/pre>\n<p>11\u3001linux\u4e2d\u6279\u91cf\u6740\u6b7bmysql\u4e3asleep\u7684\u8fde\u63a5<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\necho &quot;`date` killing mysql sleep process...&quot; &gt;&gt; \/tmp\/crontab.log\r\nfor id in `mysql -u root -pYourPassword, -e &quot;show processlist&quot;|grep -i -E 'sleep|locked'  | awk '{if($6&gt;100){print $1}}'`\r\ndo\r\n  echo &quot;killing pid $id&quot; &gt;&gt; \/tmp\/crontab.log\r\n  echo `mysql -u root -pYourPassword, -e &quot;kill $id&quot;`\r\ndone\r\n<\/pre>\n<p>12\u3001mysql\u4e2d\u6709\u54ea\u4e9b\u5b58\u50a8\u5f15\u64ce<\/p>\n<p>13\u3001mysql\u4fee\u6539\u8868test\u4e3b\u952e\u4e3aid\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u6dfb\u52a0\u552f\u4e00\u952e\r\nALTER TABLE `test2` ADD UNIQUE ( `userid`)\r\n\u4fee\u6539\u4e3b\u952e\r\nALTER TABLE `test2` DROP PRIMARY KEY ,ADD PRIMARY KEY ( `id` )\r\n\u589e\u52a0\u7d22\u5f15\r\nALTER TABLE `test2` ADD INDEX ( `id` )\r\n<\/pre>\n<p>14\u3001mysql\u8ba1\u7b97\u65e5\u671f&#8217;2013-01-14 20:34:47&#8217;\u5411\u524d\u63a8\u4e09\u5929\u662f\u54ea\u4e00\u5929\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nselect date_sub('2013-01-14 20:34:47', interval 3 day);\r\n<\/pre>\n<p>15\u3001$str1 = null; $str2 = false; echo $str1 == $str2 ? &#8216;\u76f8\u7b49&#8217; : &#8216;\u4e0d\u76f8\u7b49&#8217;;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n  \u76f8\u7b49\r\n<\/pre>\n<p>16\u3001\u4e0b\u9762\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/A.php\r\n&lt;?php\r\nfunction Test_Global(){\r\n\tinclude 'B.php';\r\n\tTest();\r\n}\r\n\r\n$a = 0;\r\nTest_Global();\r\necho $a;\r\n\r\n?&gt;\r\n\r\n\/\/B.php\u6587\u4ef6\r\n&lt;?php\r\nfunction Test(){\r\n\tglobal $a;\r\n\t$a -= 1;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u7b54\u6848\u4e3a-1<\/p>\n<p>17\u3001\u4e0b\u9762\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction getCount(){\r\n\tstatic $count = 3;\r\n\treturn $count++;\r\n}\r\n\r\nfunction getCounts(&amp;$count){\r\n\tunset($count);\r\n\t$count = 1;\r\n}\r\n\r\n$count = 5;\r\ngetCounts($count);\r\necho $count;\r\n++$count;\r\necho $count;\r\necho getCount();\r\necho getCount();\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n5\r\n6\r\n3\r\n4\r\n<\/pre>\n<p>18\u3001\u4f7f\u7528php\u7684\u4e8c\u5206\u6cd5\u67e5\u627e\u7b97\u6cd5\u8f93\u51fa\u6570\u7ec4 $arr = array(1,2,3,4,5,6,7,8,9,12,23,33,35,56,67,89,99)\u4e2d33\u7684\u4e0b\u6807\u3002<\/p>\n<p>19\u3001\u7b80\u8ff0mysql\u7684\u5206\u533a\u548c\u5206\u8868\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u4e48\u662f\u5206\u8868\uff0c\u4ece\u8868\u9762\u610f\u601d\u4e0a\u770b\u5462\uff0c\u5c31\u662f\u628a\u4e00\u5f20\u8868\u5206\u6210N\u591a\u4e2a\u5c0f\u8868\r\n\u4ec0\u4e48\u662f\u5206\u533a\uff0c\u5206\u533a\u5462\u5c31\u662f\u628a\u4e00\u5f20\u8868\u7684\u6570\u636e\u5206\u6210N\u591a\u4e2a\u533a\u5757\uff0c\u8fd9\u4e9b\u533a\u5757\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u78c1\u76d8\u4e0a\uff0c\u4e5f\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u78c1\u76d8\u4e0a\r\n<\/pre>\n<p>20\u3001\u5047\u8bbea.html\u548cb.html\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e0b\u9762\uff0c\u7528javascript\u5b9e\u73b0\u5f53\u6253\u5f00a.html\u4e94\u79d2\u949f\u540e\uff0c\u81ea\u52a8\u8df3\u8f6c\u5230b.html\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n      window.onload = function (){\r\n          setTimeout(function(){window.location.href = 'b.html'}, 5000)\r\n      }\r\n<\/pre>\n<p>=========================================================<\/p>\n<p>1\u3001Python\u5982\u4f55\u5b9e\u73b0\u5355\u4f8b\u6a21\u5f0f\uff1f<\/p>\n<p>Python\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u5355\u4f8b\u6a21\u5f0f\uff0c\u4e0b\u9762\u4e24\u4e2a\u4f8b\u5b50\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u65b9\u5f0f\u5b9e\u73b0\u5355\u4f8b\u6a21\u5f0f\uff1a<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass Singleton(type):\r\n    def __init__(cls, name, bases, dict):\r\n        super(Singleton, cls).__init__(name, bases, dict)\r\n        cls.instance = None\r\n\r\n    def __call__(cls, *args, **kw):\r\n        if cls.instance is None:\r\n        cls.instance = super(Singleton, cls).__call__(*args, **kw)\r\n        return cls.instance\r\n\r\nclass MyClass(object):\r\n    __metaclass__ = Singleton\r\n\r\nprint MyClass()\r\nprint MyClass()\r\n<\/pre>\n<p>\u4f7f\u7528decorator\u6765\u5b9e\u73b0\u5355\u4f8b\u6a21\u5f0f<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef singleton(cls):\r\n    instances = {}\r\n    def getinstance():\r\n        if cls not in instances:\r\n        instances&#x5B;cls] = cls()\r\n        return instances&#x5B;cls]\r\n   return getinstance\r\n\r\n@singleton\r\nclass MyClass:\r\n\u2026\r\n<\/pre>\n<p>2\u3001\u4ec0\u4e48\u662flambda\u51fd\u6570\uff1f<\/p>\n<p>Python\u5141\u8bb8\u4f60\u5b9a\u4e49\u4e00\u79cd\u5355\u884c\u7684\u5c0f\u51fd\u6570\u3002\u5b9a\u4e49lambda\u51fd\u6570\u7684\u5f62\u5f0f\u5982\u4e0b\uff1alabmda \u53c2\u6570\uff1a\u8868\u8fbe\u5f0flambda\u51fd\u6570\u9ed8\u8ba4\u8fd4\u56de\u8868\u8fbe\u5f0f\u7684\u503c\u3002<br \/>\n\u4f60\u4e5f\u53ef\u4ee5\u5c06\u5176\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002lambda\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u4efb\u610f\u4e2a\u53c2\u6570\uff0c\u5305\u62ec\u53ef\u9009\u53c2\u6570\uff0c\u4f46\u662f\u8868\u8fbe\u5f0f\u53ea\u6709\u4e00\u4e2a\uff1a<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt; g = lambda x, y: x*y\r\n&gt;&gt;&gt; g(3,4)\r\n12\r\n<\/pre>\n<p>3\u3001Python\u662f\u5982\u4f55\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u7684\uff1f<\/p>\n<p>Python\u63d0\u4f9b\u4e86\u5c06\u53d8\u91cf\u6216\u503c\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u6362\u6210\u53e6\u4e00\u79cd\u7c7b\u578b\u7684\u5185\u7f6e\u51fd\u6570\u3002int\u51fd\u6570\u80fd\u591f\u5c06\u7b26\u5408\u6570\u5b66\u683c\u5f0f\u6570\u5b57\u578b\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6574\u6570\u3002\u5426\u5219\uff0c\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt; int(\u201c34\u2033)\r\n34\r\n&gt;&gt;&gt; int(\u201c1234ab\u201d) #\u4e0d\u80fd\u8f6c\u6362\u6210\u6574\u6570\r\nValueError: invalid literal for int(): 1234ab\r\n<\/pre>\n<p>4\u3001Python\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u51fd\u6570\u7684\u5b9a\u4e49\u5f62\u5f0f\u5982\r\n\u4e0b\uff1a\r\ndef (arg1, arg2,\u2026 argN):\r\n  ....\r\n  return ...\r\n<\/pre>\n<p>5\u3001Python\u662f\u5982\u4f55\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\u7684\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nPython\u63d0\u4f9b\u4e86\u5bf9\u5185\u5b58\u7684\u5783\u573e\u6536\u96c6\u673a\u5236\uff0c\u4f46\u662f\u5b83\u5c06\u4e0d\u7528\u7684\u5185\u5b58\u653e\u5230\u5185\u5b58\u6c60\u800c\u4e0d\u662f\u8fd4\u56de\u7ed9\u64cd\u4f5c\u7cfb\u7edf\u3002\r\n<\/pre>\n<p>6\u3001\u5982\u4f55\u53cd\u5e8f\u7684\u8fed\u4ee3\u4e00\u4e2a\u5e8f\u5217\uff1f<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\na = &#x5B;1, 2, 3, 4, 5]\r\nfor x in a&#x5B;::-1]:\r\n\tprint x,\r\n<\/pre>\n<p>7\u3001Python\u91cc\u9762\u5982\u4f55\u5b9e\u73b0tuple\u548clist\u7684\u8f6c\u6362\uff1f<\/p>\n<p>\u4f7f\u7528tuple()\u548clist()\u5c31\u76f4\u63a5\u53ef\u4ee5\u8f6c\u6362\u4e86<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt;tuple(&#x5B;1,2])\r\n(1, 2)\r\n&gt;&gt;&gt; list((1,2))\r\n&#x5B;1, 2]\r\n<\/pre>\n<p>8\u3001\u8bf7\u5199\u51fa\u4e00\u6bb5python\u4ee3\u7801\u5b9e\u73b0\u5220\u9664\u4e00\u4e2alist\u91cc\u9762\u7684\u91cd\u590d\u5143\u7d20\u3002<\/p>\n<p>\u4f7f\u7528set<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt;a=&#x5B;1, 2, 2, 3, 2, 1, 5, 4]\r\n&gt;&gt;&gt;list(set(a))\r\n&#x5B;1, 2, 3, 4, 5]\r\n<\/pre>\n<p>9\u3001\u5982\u4f55\u7528python\u5220\u9664\u4e00\u4e2a\u6587\u4ef6\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport os\r\n\u5220\u9664\u6587\u4ef6\uff1a\r\nos.remove()\r\n\u5220\u9664\u7a7a\u76ee\u5f55\uff1a\r\nos.rmdir()\r\n\u9012\u5f52\u5220\u9664\u7a7a\u76ee\u5f55\uff1a\r\nos.removedirs()\r\n<\/pre>\n<p>10\u3001python\u5982\u4f55copy\u4e00\u4e2a\u6587\u4ef6\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nshutil.copyfile:\u5982\u4f55\u590d\u5236\u6587\u4ef6\r\nos.path.exists:\u5982\u4f55\u5224\u65ad\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\r\nshutil.copytree:\u5982\u4f55\u590d\u5236\u76ee\u5f55\u6811\r\n<\/pre>\n<p>11\u3001python\u91cc\u9762\u5982\u4f55\u751f\u6210\u968f\u673a\u6570\uff1f<\/p>\n<p>\u4f7f\u7528random\u5e93<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt;import random\r\n&gt;&gt;&gt;random.random()\r\n0.65210770661102258\r\n&gt;&gt;&gt; random.randint(1, 100)\r\n93\r\n<\/pre>\n<p>12\u3001\u5982\u4f55\u7528python\u6765\u53d1\u90ae\u4ef6\uff1f<\/p>\n<p>\u4e3b\u8981\u4f7f\u7528smtplib\u5e93<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nsmtp = smtplib.SMTP()\r\ntry  :\r\n      smtp.set_debuglevel( 1 )\r\n      smtp.connect(&quot; server &quot;)\r\n      smtp.login(&quot; user &quot;, &quot; password&quot;)\r\nexcept :\r\n      print &quot; smtp login exception! &quot;\r\nsmtp.sendmail(fromaddr, toaddrs, msg)\r\nsmtp.quit()\r\n<\/pre>\n<p>13\u3001python\u91cc\u9762\u5982\u4f55\u62f7\u8d1d\u4e00\u4e2a\u5bf9\u8c61\uff1f<\/p>\n<p>\u6807\u51c6\u5e93\u4e2d\u7684copy\u6a21\u5757\u63d0\u4f9b\u4e86\u4e24\u4e2a\u65b9\u6cd5\u6765\u5b9e\u73b0\u62f7\u8d1d.\u4e00\u4e2a\u65b9\u6cd5\u662fcopy,\u5b83\u8fd4\u56de\u548c\u53c2\u6570\u5305\u542b\u5185\u5bb9\u4e00\u6837\u7684\u5bf9\u8c61.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nimport copy\r\nnew_list = copy.copy(existing_list)\r\n<\/pre>\n<p>\u6709\u4e9b\u65f6\u5019,\u4f60\u5e0c\u671b\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u4e5f\u88ab\u590d\u5236,\u53ef\u4ee5\u4f7f\u7528deepcopy\u65b9\u6cd5:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport copy\r\nnew_list_of_dicts = copy.deepcopy(existing_list_of_dicts)\r\n<\/pre>\n<p>14\u3001\u6709\u6ca1\u6709\u4e00\u4e2a\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u67e5\u627epython\u7684bug\u548c\u9759\u6001\u7684\u4ee3\u7801\u5206\u6790\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u6709\uff0cPyChecker\u662f\u4e00\u4e2apython\u4ee3\u7801\u7684\u9759\u6001\u5206\u6790\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u67e5\u627epython\u4ee3\u7801\u7684bug, \u4f1a\u5bf9\u4ee3\u7801\u7684\u590d\u6742\u5ea6\u548c\u683c\u5f0f\u63d0\u51fa\u8b66\u544a\r\nPylint\u662f\u53e6\u5916\u4e00\u4e2a\u5de5\u5177\u53ef\u4ee5\u8fdb\u884ccoding standard\u68c0\u67e5\u3002\r\n<\/pre>\n<p>15\u3001\u5982\u4f55\u5728\u4e00\u4e2afunction\u91cc\u9762\u8bbe\u7f6e\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nglobal \u8bed\u53e5\u3002\u5728function\u7684\u5f00\u59cb\u63d2\u5165\u4e00\u4e2aglobal\u58f0\u660e\uff1a\r\ndef f():\r\n    global x\r\n<\/pre>\n<p>16\u3001\u6709\u4e24\u4e2a\u5e8f\u5217a\uff0cb\uff0c\u5927\u5c0f\u90fd\u4e3an\uff0c\u5e8f\u5217\u5143\u7d20\u7684\u503c\u4e3a\u4efb\u610f\u6574\u5f62\u6570\uff0c\u65e0\u5e8f\u3002\u8981\u6c42\u4ea4\u6362a\u3001b\u4e2d\u7684\u5143\u7d20\uff0c\u4f7f[\u5e8f\u5217a\u5143\u7d20\u7684\u548c]\u4e0e[\u5e8f\u5217b\u5143\u7d20\u7684\u548c]\u4e4b\u95f4\u5dee\u6700\u5c0f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n* \u5c06\u4e24\u5e8f\u5217\u5408\u5e76\u4e3a\u4e00\u4e2a\u5e8f\u5217\uff0c\u5e76\u6392\u5e8f\uff0c\u4e3a\u5e8f\u5217Source\r\n* \u62ff\u51fa\u6700\u5927\u5143\u7d20Big\uff0c\u6b21\u5927\u7684\u5143\u7d20Small\r\n* \u5728\u4f59\u4e0b\u7684\u5e8f\u5217S&#x5B;:-2]\u8fdb\u884c\u5e73\u5206\uff0c\u5f97\u5230\u5e8f\u5217max\uff0cmin\r\n* \u5c06Small\u52a0\u5230max\u5e8f\u5217\uff0c\u5c06Big\u52a0\u5927min\u5e8f\u5217\uff0c\u91cd\u65b0\u8ba1\u7b97\u65b0\u5e8f\u5217\u548c\uff0c\u548c\u5927\u7684\u4e3amax\uff0c\u5c0f\u7684\u4e3amin\u3002\r\n<\/pre>\n<p>17\u3001\u7528python\u5339\u914dhtml tag\u7684\u65f6\u5019\uff0c\u548c\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u8d2a\u5a6a\u4e0e\u975e\u8d2a\u5a6a\r\n<\/pre>\n<p>18\u3001python\u91cc\u9762search()\u548cmatch()\u7684\u533a\u522b\uff1f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmatch\uff08\uff09\u51fd\u6570\u53ea\u68c0\u6d4bRE\u662f\u4e0d\u662f\u5728string\u7684\u5f00\u59cb\u4f4d\u7f6e\u5339\u914d\uff0c search()\u4f1a\u626b\u63cf\u6574\u4e2astring\u67e5\u627e\u5339\u914d,\r\n\u4e5f\u5c31\u662f\u8bf4match\uff08\uff09\u53ea\u6709\u57280\u4f4d\u7f6e\u5339\u914d\u6210\u529f\u7684\u8bdd\u624d\u6709\u8fd4\u56de\uff0c\u5982\u679c\u4e0d\u662f\u5f00\u59cb\u4f4d\u7f6e\u5339\u914d\u6210\u529f\u7684\u8bdd\uff0cmatch()\u5c31\u8fd4\u56denone\r\n\r\n\u4f8b\u5982\uff1a\r\n\r\nprint(re.match(\u2018super\u2019, \u2018superstition\u2019).span())\u4f1a\u8fd4\u56de(0, 5)\r\n\u800c print(re.match(\u2018super\u2019, \u2018insuperable\u2019))\u5219\u8fd4\u56deNone\r\n\r\nsearch()\u4f1a\u626b\u63cf\u6574\u4e2a\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de\u7b2c\u4e00\u4e2a\u6210\u529f\u7684\u5339\u914d\r\n\r\n\u4f8b\u5982\uff1aprint(re.search(\u2018super\u2019, \u2018superstition\u2019).span())\u8fd4\u56de(0, 5)\r\n\r\nprint(re.search(\u2018super\u2019, \u2018insuperable\u2019).span())\u8fd4\u56de(2, 7)\r\n<\/pre>\n<p>19\u3001\u5982\u4f55\u7528python\u6765\u8fdb\u884c\u67e5\u8be2\u548c\u66ff\u6362\u4e00\u4e2a\u6587\u672c\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\na = 'hello word'\r\n\u6211\u628aa\u5b57\u7b26\u4e32\u91cc\u7684word\u66ff\u6362\u4e3apython\r\n1\u7528\u5b57\u7b26\u4e32\u672c\u8eab\u7684replace\u65b9\u6cd5\r\na.replace('word','python')\r\n\u8f93\u51fa\u7684\u7ed3\u679c\u662fhello python\r\n\r\n2\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5b8c\u6210\u66ff\u6362:\r\nimport re\r\nstrinfo = re.compile('word')\r\nb = strinfo.sub('python',a)\r\nprint b\r\n\u8f93\u51fa\u7684\u7ed3\u679c\u4e5f\u662fhello python\r\n<\/pre>\n<p>20\u3001\u4ecb\u7ecd\u4e00\u4e2aexcept\u7684\u7528\u6cd5\u548c\u4f5c\u7528\u3002<\/p>\n<p>Python\u7684except\u7528\u6765\u6355\u83b7\u6240\u6709\u5f02\u5e38\uff0c \u56e0\u4e3aPython\u91cc\u9762\u7684\u6bcf\u6b21\u9519\u8bef\u90fd\u4f1a\u629b\u51fa \u4e00\u4e2a\u5f02\u5e38\uff0c\u6240\u4ee5\u6bcf\u4e2a\u7a0b\u5e8f\u7684\u9519\u8bef\u90fd\u88ab\u5f53\u4f5c\u4e00\u4e2a\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntry:\r\n    foo = opne(\u201cfile\u201d) # \u8fd9\u65f6\u5019except\u53ea\u6355\u83b7IOError\r\nexcept IOError:\r\n    sys.exit(\u201ccould not open file\u201d)\r\n<\/pre>\n<p>21\u3001python\u4e2dpass\u8bed\u53e5\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\u4ec0\u4e48\u90fd\u4e0d\u505a\uff0c\u7a7a\u64cd\u4f5c\u3002\r\n<\/pre>\n<p>22\u3001\u4ecb\u7ecd\u4e00\u4e0bpython\u4e0brange()\u51fd\u6570\u7684\u7528\u6cd5\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n&gt;&gt;&gt; range(10)\r\n&#x5B;0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\n&gt;&gt;&gt; range(1, 11)\r\n&#x5B;1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n&gt;&gt;&gt; range(0, 30, 5)\r\n&#x5B;0, 5, 10, 15, 20, 25]\r\n&gt;&gt;&gt; range(0, 10, 3)\r\n&#x5B;0, 3, 6, 9]\r\n&gt;&gt;&gt; range(0, -10, -1)\r\n&#x5B;0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\r\n&gt;&gt;&gt; range(0)\r\n&#x5B;]\r\n&gt;&gt;&gt; range(1, 0)\r\n&#x5B;]\r\n<\/pre>\n<p>=========================================================<\/p>\n<p>1\u3001\u8fd0\u884c\u4e0b\u9762\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1f<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\t$global_obj = null;\r\n\tclass my_class {\r\n\t\tvar $value;\r\n\t\tfunction my_class(){\r\n\t\t\tglobal $global_obj;\r\n\t\t\t$global_obj = &amp;$this;\r\n\t\t}\r\n\r\n\t}\r\n\r\n\t$a = new my_class();\r\n\t$a-&gt;my_value = 50;\r\n\t$global_obj-&gt;my_value = 100;\r\n\techo $a-&gt;my_value;\r\n\r\n?&gt;\r\n<\/pre>\n<p>\u7b54\u6848\u4e3a50<\/p>\n<p>2\u3001\u8fd0\u884c\u4e0b\u9762\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1f<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\tclass my_class {\r\n\t\tvar $value;\r\n\t}\r\n\r\n\t$a = new my_class();\r\n\t$a-&gt;my_value = 5;\r\n\t$b = $a;\r\n\t$b-&gt;my_value = 10;\r\n\techo $a-&gt;my_value;\r\n\r\n?&gt;\r\n<\/pre>\n<p>\u7b54\u6848\u4e3a10<\/p>\n<p>3\u3001\u8fd0\u884c\u4e0b\u9762\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1f<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\tdefine('myvalue', '10');\r\n\t$var = 'abs_system';\r\n\t$myarray&#x5B;10] = 'Dog';\r\n\t$myarray&#x5B;] = 'Human';\r\n\t$myarray&#x5B;'myvalue'] = 'Cat';\r\n\t$myarray&#x5B;'Dog'] = 'Cat';\r\n\tprint 'The value is:';\r\n\tprint $myarray&#x5B;myvalue].$var{2}.'\\n';\r\n\r\n?&gt;\r\n<\/pre>\n<p>\u7b54\u6848\u4e3a The value is:Dogs\\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f\u6211\u6700\u8fd1\u9762\u8bd5\u9047\u5230\u7684\u4e00\u4e9b\u9762\u8bd5\u9898\u76ee\uff0c\u662f\u6211\u505a\u5b8c\u540e\u7528\u624b\u673a\u62cd\u4e0b\u56de\u6765\u6574\u7406\u51fa\u6765\u7684\u3002\u7edd\u5927\u90e8\u5206\u9898\u76ee\u90fd\u662f\u76f4\u63a5\u5728\u7f51\u4e0a\u53ef\u4ee5\u5f88\u5bb9\u6613\u627e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2570","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=2570"}],"version-history":[{"count":4,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2570\/revisions"}],"predecessor-version":[{"id":2573,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/2570\/revisions\/2573"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=2570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=2570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=2570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}