Home  >  Article  >  Backend Development  >  In-depth understanding of PHP array traversal order

In-depth understanding of PHP array traversal order

WBOY
WBOYOriginal
2016-08-08 09:21:42889browse
People often ask me, if a PHP array is accessed using foreach, is the order of traversal fixed? In what order?
For example:
<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>
Another example:
<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>
To fully understand this issue, I think first of all, everyone should understand the internal implementation structure of PHP arrays...PHP arraysIn PHP, arrays are implemented using a HASH structure (HashTable). PHP uses some mechanisms to make it possible Adding and deleting arrays is achieved with O(1) time complexity, and supports both linear traversal and random access. Also discussed in previous articles, PHP's HASH algorithm, Based on this, we will make further extensions. Before getting to know HashTable, let us first take a look at the structure definition of HashTable. I have added comments for everyone to understand:
<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>
Regarding the meaning of nApplyCount, we can understand it through an example:
<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>
This field is set up to prevent infinite loops caused by circular references.Looking at the above structure, we can see that for HashTable, the key element is arBuckets, which is the actual storage container. Let's take a look at it Structure definition:
<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>
We noticed that the last element, this is a flexible array technique, which can save memory and facilitate initialization. Friends who are interested can google flexible array.There are a couple of things it could refer to. The only place I've seen thatprecisewording used much is C99 though.A flexible array member is the official C99 name for what used to (usually) be called the "struct hack". The basic idea is that you define a struct something like this:struct x { int a; // whatever members you want here. size_t size; int x[]; // no size, last member only }; This is used primarily (or exclusively) with dynamic allocation. When you want to allocate an object of this type, you
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn