算一个数组的PHP [英] Count an array php

查看:212
本文介绍了算一个数组的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

a  , b , c   , d                 , e  , f
375, 52, 1892, http://example.com, ::1, 1308233412
341, 52, 1892, http://example.com, ::1, 1308233412
422, 52, 1892, http://example.com, ::1, 1308233417
478, 50, 1892, http://example.com, ::1, 1308233418
58, 481, 1892, http://example.com, ::1, 1308233432
69, 481, 1892, http://example.com, ::1, 1308233432
487, 49, 1892, http://example.com, ::1, 1308233432


  • A =位置y

  • B =位置x

  • C =屏幕分辨率(浏览器)

  • D =主机

  • E = IP

  • F =时间戳

  • 什么我想要做的是,例如:

    what do i want to do is, for example:

    检查,如果它在一个50x50px框,如果算上这么+1。

    check if it in a 50x50px box if so count +1.

    所以我将不得不像一个表:

    so i would have a table like:

    y/x |  0 | 50  | 100  | 150
    ----+----+-----+------+----
    50  | 0  |  1  |   2  |   0
    100 | 0  |  0  |   1  |   0
    150 | 1  |  0  |   0  |   1
    200 | 2  |  2  |   3  |   0
    etc.
    

    希望有人能帮助我实现这个上面

    Hoping somebody can help me to achieve this above

    他下面的链接是创建一个热图, http://www.design - code.nl /例子/ heatmap.php ,但热图是重叠的,所以我希望把绿点在被计数的数组,这些地区的地方是50×50内将一个突出其它颜色。对不起,信息不畅

    he following link is creating a heatmap, http://www.design-code.nl/example/heatmap.php , but the heatmap is overlapping so i want to put the green dots in an array which is counted, and those area's where it is within 50x50 will highlight with an other color. Sorry for the poor information

    推荐答案

    虽然这个问题的措辞不好,我想我明白你问什么。下面是你应该做的。我不是在PHP所有的流畅,所以请确保您查看我写的,而不是复制/粘贴它们code片段。

    While this question is poorly worded, I think I understand what you are asking for. Here's what you should do. I am not all that fluent in php so please make sure that you look over the code snippets that I write instead of copy/pasting them.


    1. 找到最大的X和Y值。

    2. 实例化和初始化的基础上那些50分值的二维数组。

    例如,如果你想数组[X] [Y] 你会怎么做:

    For instance if you wanted Array[X][Y] you would do:

    $myArray = array();
    for ($x = 0; $x < $maxX / 50; $x++) {
        $myArray[] = array();
        for ($y = 0; $y < $maxY / 50; $y++) {
            $myArray[$x][] = 0;
        }
    }
    

    这应该实例化和初始化一个二维数组所有0就像你需要

    This should instantiate and initialize a 2D array to all 0's just like you need

    3)通过你的数组,每个条目迭代,增量 $ myArray的[$ curX / 50] [$ CURY / 50] 1的值:

    3) Iterate through your array and for each entry, increment the value of $myArray[$curX/50][$curY/50] by 1:

    foreach ($inputArray as $curRow) $myArray[$curRow[b]/50][$curRow[a]/50] += 1;
    

    再次我在PHP中没有亲和确实刚开始使用它,但这应该是一个好的开始。

    Again, I'm no pro at php and have really just started working with it, but this should be a good start.

    这篇关于算一个数组的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆