數字索引陣列根據指定key轉關聯陣列

2021-05-25 12:45:18 字數 1733 閱讀 1191

array.c

php_function(array_to_associative) else {

retval = *operand;

for (zend_hash_internal_pointer_reset_ex(z_arrval_p(*operand), &data_pos);

zend_hash_get_current_data_ex(z_arrval_p(*operand), (void **) &entry, &data_pos) == success;

zend_hash_move_forward_ex(z_arrval_p(*operand), &data_pos)

zval_add_ref(entry);

zend_hash_get_current_key_ex(z_arrval_p(*operand), &string_key, &string_key_len, &num_key, 0, &data_pos);

php_printf("%s/n", string_key);

zend_hash_get_current_data_ex(z_arrval_p(*entry), (void **) &data, &data_pos);

data_type = z_type_pp(data);

php_printf("%d/n", data_type);

if (strcmp(string_key, key_name) == 0) {

switch (data_type) {

case is_string:

php_printf("%s/n", z_strval_pp(data));

zend_hash_update(z_arrval_p(return_value), z_strval_pp(data), z_strlen_pp(data) + 1, &retval, sizeof (zval *), null);

break;

case is_long:

php_printf("%d/n", z_lval_pp(data));

zend_hash_index_update(z_arrval_p(return_value), z_lval_pp(data), &retval, sizeof (zval *), null);

break;

case is_double:

php_printf("%5.5f/n", z_dval_pp(data));

zend_hash_index_update(z_arrval_p(return_value), z_dval_pp(data), &retval, sizeof (zval *), null);

break;

break;

basic_functions.c

php_fe(array_to_associative, arginfo_array_to_associative)

zend_begin_arg_info(arginfo_array_to_associative, 0)

zend_arg_info(0, arg) /* array_info(0, arg, 0) */

zend_arg_info(0, key_name)

zend_end_arg_info()

php_array.h

php_function(array_to_associative);

字典陣列根據某key排序

字典是程式設計中常用的資料結構,由多個字典組成的陣列也比較常見。有時候我們需要將字典組成的陣列根據其中乙個值進行排序。下面是乙個用python寫的 利用氣泡排序演算法寫的方法 coding utf 8 import sys reload sys sys.setdefaultencoding utf8...

索引陣列轉換成按指定鍵做key的關聯陣列

把索引陣列轉換成按指定鍵做key的關聯陣列,沒有相應key的元素將被捨棄 把索引陣列轉換成按指定鍵做key的關聯陣列,沒有相應key的元素將被捨棄 主要用做列表轉化 param array array param indexname string 對應的鍵名,值內容應為string,或可以轉為str...

PHP刪除Array陣列裡指定的key

php除陣列指定的key值 直接刪除key值實現 param unknown data param unknown key return unknown function array remove data,key keys array keys data index array search ke...