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 = 时间戳
我想要做的是,例如:
检查它是否在 50x50px 框中(如果是)数+1。
所以我会有一个像这样的表格:
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.
希望有人可以帮助我实现上面的目标,
他下面的链接正在创建一个热图, http://www.design-code.nl/example/heatmap.php,但是热图是重叠的,所以我想将绿点放在一个被计数的数组中,这些区域就是它在 50x50 范围内用另一种颜色突出显示。抱歉信息贫乏
I have the following data:
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 = position y
- b = position x
- c = screen resolution (browser)
- d = host
- e = ip
- f = timestamp
what do i want to do is, for example:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我想我已经弄清楚了问题所在(请参阅我对上面问题的评论)。
我的方法是将 X 和 Y 位置除以 50,然后使用
floor()
函数从中获取整数值。这将是它们所在的盒子编号。然后您可以轻松地将其填充到数组中。
以下代码将生成您需要的数组:
然后您可以将其打印到表格中(行标题和列标题是单元格编号乘以 50)。
您可能需要预先对
$map
数组进行零填充,以便在没有任何命中的单元格中得到零,或者您可以在打印时解决这个问题;由你决定)Okay, I think I've worked out what the question is about (see my comment by the question above).
The way I'd do it is to divide the X and Y positions by 50, and use the
floor()
function to get an integer value from that. This would be the box number that they would be in.You can then populate this into an array quite easily.
The following code will produce the array you need:
Then you can just print it into a table (with the row and column headings being the cell number multiplied by 50).
You might want to zero-fill the
$map
array beforehand so that you get zeros in cells where you don't have any hits, or you can work this out when you print it; up to you)虽然这个问题措辞不好,但我想我明白你的要求。这是你应该做的。我不太精通 php,所以请确保您查看我编写的代码片段,而不是复制/粘贴它们。
例如,如果您想要
Array[X][Y]
您会这样做:这应该实例化并初始化一个 2D 数组到所有0 就像您需要的那样
3) 迭代数组,对于每个条目,将 $myArray[$curX/50][$curY/50] 的值增加 1:
同样,我不是 php 专业人士,而且刚刚开始使用它,但这应该是一个好的开始。
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.
For instance if you wanted
Array[X][Y]
you would do:This should instantiate and initialize a 2D array to all 0's just like you need
3) Iterate through your array and for each entry, increment the value of
$myArray[$curX/50][$curY/50]
by 1:Again, I'm no pro at php and have really just started working with it, but this should be a good start.
盒子的坐标将是:
通过坐标,您可以将它们填满一个 n 维数组
The coordinates of the box would be:
With the coordinates you can them full a n-dimensional array
您想要寻找一条空间填充曲线。 sfc 通常用于热图,并将 2d 复杂度降低到 1d 复杂度。您想要查找 Nick 的希尔伯特曲线空间四叉树博客。
You want to look for a space-filling-curve. A sfc is usually used for heatmaps and reduce the 2d complexity to a 1d complexity. You want to look for Nick's hilbert curve spatial quadtree blog.
首先,您需要用 0 填充数组:
其中 2000 是最大屏幕宽度/高度。然后,计算您的值,其中
$a
是您的数组:first, you need to fill an array full with 0's:
where 2000 is the maximum screen width/height. then, you count your values, where
$a
is your array: