1 PHP_FUNCTION(array_fill_keys) 2 { 3 zval *keys, *val, *entry; 4 5 if (zend_parse_parameters(ZEND_NUM_ARGS(), "az", &keys, &val) == FAILURE) { 6 return; 7 } 8 9 /* Initialize return array */ 10 array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(keys))); 11 12 // 遍歷陣列keys 13 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { 14 ZVAL_DEREF(entry); 15 Z_TRY_ADDREF_P(val); 16 /* 以陣列key值為鍵,val為值。插入返回的陣列return_value */ 17 if (Z_TYPE_P(entry) == IS_LONG) { 18 zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), val); 19 } else { 20 zend_string *key = zval_get_string(entry); 21 zend_symtable_update(Z_ARRVAL_P(return_value), key, val); 22 zend_string_release(key); 23 } 24 } ZEND_HASH_FOREACH_END(); 25 }