深入理解PHP之數組遍歷順序

WBOY
發布: 2016-08-08 09:21:42
原創
891 人瀏覽過
常常會有人問我, PHP的數組, 如果用foreach來訪問, 遍歷的順序是固定的麼? 以什麼順序遍歷呢?
比如:
<ol style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><?php</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_string" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'laruence'</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_string" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'huixinchen'</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_string" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'yahoo'</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span>    <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2007</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_string" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'baidu'</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span>    <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2008</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">foreach</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span> <span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">as</span> <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$key</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=></span> <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$val</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">)</span> <span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">{</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">//结果是什么?</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">}</span></li></ol>
登入後複製
又比如:
<ol style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><?php</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_string" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(168, 255, 96);">'huixinchen'</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">1</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span>  <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2007</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">0</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">]</span>  <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2008</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">foreach</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span> <span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">as</span> <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$key</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=></span> <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$val</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">)</span> <span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">{</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">//现在结果又是什么?</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">}</span></li></ol>
登入後複製
rreee比如:
<ol style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">typedef</span> <span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">_hashtable</span> <span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">{</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">uint</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>nTableSize<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>        <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 散列表大小, Hash值的区间 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">uint</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>nTableMask<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>        <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 等于nTableSize -1, 用于快速定位,相当于是取模 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">uint</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>nNumOfElements<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>    <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* HashTable中实际元素的个数 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">ulong</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"> </span><span style="background-color: rgb(51, 51, 51);">nNextFreeElement</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">;</span><span style="background-color: rgb(51, 51, 51);"> </span><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);"><span style="background-color: rgb(51, 51, 51);">/* 下个空闲可用位置的数字索引,</span><span style="background-color: rgb(0, 0, 153);">执行$arr[]='xxx'时使用这个值</span><span style="background-color: rgb(51, 51, 51);"> */</span></span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">Bucket</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pInternalPointer<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>   <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 内部位置指针, 会被reset, current这些遍历函数使用 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">Bucket</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pListHead<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>      <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 头元素, 用于线性遍历 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">Bucket</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pListTail<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>      <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 尾元素, 用于线性遍历 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">Bucket</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"> </span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">**</span><span style="background-color: rgb(51, 51, 51);">arBuckets</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">;</span><span style="background-color: rgb(51, 51, 51);">     </span><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);"><span style="background-color: rgb(51, 51, 51);">/* 实际的存储容器</span><span style="background-color: rgb(0, 0, 153);">(<span class="sh_usertype" style="color: rgb(246, 243, 232); font-family: inherit; font-style: inherit; font-weight: inherit; line-height: 18px; white-space: pre; margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; vertical-align: baseline;">Bucket</span><span class="sh_normal" style="color: rgb(246, 243, 232); font-family: inherit; font-style: inherit; font-weight: inherit; line-height: 18px; white-space: pre; margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; vertical-align: baseline;"> </span><span class="sh_symbol" style="color: rgb(246, 243, 232); font-family: inherit; font-style: inherit; font-weight: inherit; line-height: 18px; white-space: pre; margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; vertical-align: baseline;">**</span><span style="color: rgb(246, 243, 232); font-family: Monaco, Consolas, Courier, monospace; line-height: 18px; white-space: pre;">arBuckets</span>定义一个指针数组的另一种方式)</span><span style="background-color: rgb(51, 51, 51);"> */</span></span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">dtor_func_t</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>pDestructor<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 元素的析构函数(指针) */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">zend_bool</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>persistent<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182);">unsigned</span> <span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182);">char</span> nApplyCount<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span> <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 循环遍历保护 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">zend_bool</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>bApplyProtection<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_preproc" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 210, 167);">#if</span> ZEND_DEBUG</li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182);">int</span> inconsistent<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_preproc" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 210, 167);">#endif</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">}</span> HashTable<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li></ol>
登入後複製
又比如:
<ol style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><?php</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">    <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">array</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">1</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">2</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">3</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">4</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">,</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">5</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">,);</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">    <span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[]</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">=</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">&</span><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </li><li style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">    <span class="sh_function" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 210, 167);">var_export</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">(</span><span class="sh_variable" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(198, 197, 254);">$arr</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">);</span> <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">//Fatal error: Nesting level too deep - recursive dependency?</span></li></ol>
登入後複製
<ol style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; list-style-type: none;"><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">typedef</span> <span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">bucket</span> <span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">{</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">ulong</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>h<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>                        <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 数字索引/hash值 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_usertype" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">uint</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span>nKeyLength<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>                <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 字符索引的长度 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"><span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182); background-color: rgb(51, 51, 51);">void</span><span style="background-color: rgb(51, 51, 51);"> </span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">*</span><span style="background-color: rgb(51, 51, 51);">pData</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);">;</span><span style="background-color: rgb(51, 51, 51);">                    </span><span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);"><span style="background-color: rgb(51, 51, 51);">/* 数据,</span><span style="background-color: rgb(0, 0, 153);">指向zval结构</span><span style="background-color: rgb(51, 51, 51);"> */</span></span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182);">void</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pDataPtr<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>                 <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 数据指针 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">bucket</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pListNext<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>               <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 下一个元素, 用于线性遍历 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">bucket</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pListLast<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>       <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 上一个元素, 用于线性遍历 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">bucket</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pNext<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>                   <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 处于同一个拉链中的下一个元素 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_keyword" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(150, 203, 254);">struct</span><span class="sh_normal" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;"> </span><span class="sh_classname" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">bucket</span> <span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">*</span>pLast<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span>                   <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 处于同一拉链中的上一个元素 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_type" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 255, 182);">char</span> arKey<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">[</span><span class="sh_number" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(255, 115, 253);">1</span><span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">];</span> <span class="sh_comment" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline; color: rgb(124, 124, 124);">/* 节省内存,方便初始化的技巧 */</span></li><li style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(51, 51, 51);"><span class="sh_cbracket" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">}</span> Bucket<span class="sh_symbol" style="margin: 0px; padding: 0px; border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit; vertical-align: baseline;">;</span></li></ol>
登入後複製
我想首先應該要大家了解PHP數組的內部實現結構……
PHP的數組在PHP中, 數組是用一種HASH結構(HashTable)來實現的, PHP使用了一些機制, 使得可以在O(1)的時間複雜度下實現數組的增刪, 並同時支援線性遍歷和隨機訪問.之前的文章中也討論過, PHP的HASH演算法, 基於此, 我們做進一步的延伸.認識HashTable之前, 首先讓我們看看HashTable的結構定義, 我加了註釋方便大家理解:struct x { int a; // whatever members you want here. size_t size; int x[]; // no size, last member only }; 關於nApplyCount的意義, 我們可以透過一個例子來了解: rrreee這個字段就是為了防治循環引用導致的無限循環而設立的.查看上面的結構, 可以看出, 對於HashTable, 關鍵元素就是arBuckets了, 這個是實際存儲的容器, 讓我們來看看它的結構定義:rrreee我們注意到, 最後一個元素, 這個是flexible array技巧, 可以節省內存,和方便初始化的一種做法, 有興趣的朋友可以google flexible array.There are a couple of things it could refer to. The only place I've seen that precise 🎜wording used much is C99 though.🎜🎜A flexible array cally 00000m 00000us flexis to Hally A flexible 79be 0000us 45) 000us flexis for Sperion 909000) toa 45) toa flexis forion 905) toa 4 月)為 985) 000us 45) 000y 好的y fionyion sat forion​​ion yionion for mally sionhem 0hus flex 9)'s 000us 4m. flex 98900) toa flexis 05 月 909000) toa 0 月)。 "struct hack". The basic idea is that you define a struct something like this:🎜rrreee🎜This is used primarily (or exclusively) with dynamic allocation. When you want to allocate an object of this an
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板