找回密码
 加入
搜索
楼主: 网店

[效率算法] 已解决如何按数组每间隔100执行循环

 火... [复制链接]
发表于 2012-4-19 00:27:19 | 显示全部楼层
新人,过来学习,帮顶。
 楼主| 发表于 2012-4-19 08:14:46 | 显示全部楼层
回复 30# netegg


    曰:就是为了插进数据库 取全数据
发表于 2012-4-19 08:36:03 | 显示全部楼层
回复 32# 网店
那和100有什么关系
 楼主| 发表于 2012-4-19 09:00:38 | 显示全部楼层
回复 33# netegg


    参数数量最大支持100个 如能支持2000个 执行一次就可以了 这点问题总要纠结呢。。。。
发表于 2012-4-19 09:02:50 | 显示全部楼层
回复 34# 网店
你这些参数是自定义的还是从数据库提出来的
 楼主| 发表于 2012-4-19 09:04:29 | 显示全部楼层
回复 33# netegg


    PHP数组教程(006) 分割数组 array_chunk()

array array_chunk ( array input, int size [, bool preserve_keys] ) array_chunk() 将一个数组分割成多个数组,其中每个数组的单元数目由 size 决定。最后一个数组的单元数目可能会少几个。得到的数组是一个多维数组中的单元,其索引从零开始
 楼主| 发表于 2012-4-19 09:08:02 | 显示全部楼层
PHP_FUNCTION(array_chunk)
{
        int argc = ZEND_NUM_ARGS(), key_type, num_in;
        long size, current = 0;
        char *str_key;
        uint str_key_len;
        zval *input = NULL;
        zval *chunk = NULL;
        zval **entry;
        HashPosition pos;

        if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) {                return;
        }            
        /* Do bounds checking for size parameter. */
        if (size < 1) {
                return;
        }
       //获取数组元素个数
        num_in = zend_hash_num_elements(Z_ARRVAL_P(input));
         //如果分割的个数大于 数组的元素
        if (size > num_in) {
                最小为1
                size = num_in > 0 ? num_in : 1;
        }
        //初始化返回值return_value
        array_init_size(return_value, ((num_in - 1) / size) + 1);
        //数组当前执行的元素指针
        zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
        while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void**)&entry, &pos) == SUCCESS) {
                /* If new chunk, create and initialize it. */
                if (!chunk) {
                        MAKE_STD_ZVAL(chunk);
                        array_init_size(chunk, size);
                }
                zval_add_ref(entry);
                if (preserve_keys) { //如果保存原来的键值
                         //获取当前指针的key
                         key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, &str_key_len, &num_key, 0, &pos);
                        switch (key_type) {
                                case HASH_KEY_IS_STRING://键值是字符串,将key和值添加到chunk里
                                        add_assoc_zval_ex(chunk, str_key, str_key_len, *entry);
                                        break;
                                default:
                                        add_index_zval(chunk, num_key, *entry);
                                        break;
                        }
                } else {//重建数组索引 只将entry数据添加到chunki里
                        add_next_index_zval(chunk, *entry);
                }

                /* If reached the chunk size, add it to the result array, and reset the
                 * pointer. */
                if (!(++current % size)) {
                        add_next_index_zval(return_value, chunk);
                        chunk = NULL;
                }
                //移动到下一元素
                zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
        }

        /* Add the final chunk if there is one. */
       //添加到返回值return_value的Hash里
        if (chunk) {
                add_next_index_zval(return_value, chunk);
        }
}
 楼主| 发表于 2012-4-19 09:17:50 | 显示全部楼层
本帖最后由 网店 于 2012-4-19 18:29 编辑

回复 35# netegg




参数在数组里
发表于 2012-4-19 10:37:29 | 显示全部楼层
回复 38# 网店
楼主早点把问题说明白也许早就已经解决了.
何必像挤牙膏一样问一句挤一句呢?

#include <array.au3>
Local $Arr[3006]

For $i=0 to UBound($Arr)-1;初始化数组
        $Arr[$i]="SZ"&StringFormat('%06d',Random(1,999999,1))
Next

For $i=0 to UBound($Arr)-1 Step 100;是按100步进吗?
        Local $str=''
        For $n=$i to $i+100;步进为1
                If $n> UBound($Arr)-1 Then ExitLoop;避免数组越界
                $str&=$Arr[$n]&","
        Next
        $str=StringTrimRight($str,1)
        MsgBox(0,0,$str)
Next

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-4-19 12:00:42 | 显示全部楼层
本帖最后由 网店 于 2012-4-19 12:10 编辑

回复 39# 3mile


    解决
另问:
用 InetGet 取得文本如何不被再次覆盖?如何追加到文件尾??
发表于 2012-4-19 21:08:56 | 显示全部楼层
回复 40# 网店
查看一下fileopen()函数的说明就明白鸟
发表于 2012-4-20 19:52:51 | 显示全部楼层
我是来学习和打酱油的。。。
发表于 2012-5-9 16:54:27 | 显示全部楼层
结合看还是没懂
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-13 09:15 , Processed in 0.084912 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表