(PECL quickhash >= 未知)
QuickHashIntHash::loadFromString — 此工廠方法從字串建立雜湊
$contents
, int $options
= ?): QuickHashIntHash此工廠方法從字串中的定義建立新的雜湊。檔案格式由 32 位元帶符號整數組成,這些整數以程式碼執行所在系統使用的位元組順序打包在一起。對於每個元素,儲存兩個 32 位元帶符號整數。每個元素的第一個是鍵,第二個是屬於該鍵的值。
contents
包含雜湊序列化格式的字串。
options
此方法接受與類別建構子相同的選項,但 `size` 選項會被忽略。它會自動計算為雜湊表中項目的數量,向上捨入至最接近的 2 的次方,最大限制為 4194304
。
回傳一個新的 QuickHashIntHash 物件。
範例 #1 QuickHashIntHash::loadFromString() 範例
<?php
$contents = file_get_contents( dirname( __FILE__ ) . "/simple.hash" );
$hash = QuickHashIntHash::loadFromString(
$contents,
QuickHashIntHash::DO_NOT_USE_ZEND_ALLOC
);
foreach( range( 0, 0x0f ) as $key )
{
printf( "金鑰 %3d (%2x) %s\n",
$key, $key,
$hash->exists( $key ) ? '已設定' : '未設定'
);
}
?>
上述範例的輸出結果類似如下:
Key 0 ( 0) is unset Key 1 ( 1) is set Key 2 ( 2) is set Key 3 ( 3) is set Key 4 ( 4) is unset Key 5 ( 5) is set Key 6 ( 6) is unset Key 7 ( 7) is set Key 8 ( 8) is unset Key 9 ( 9) is unset Key 10 ( a) is unset Key 11 ( b) is set Key 12 ( c) is unset Key 13 ( d) is set Key 14 ( e) is unset Key 15 ( f) is unset