English 中文(简体)
PHP 多种语文
原标题:PHP Multidimensional Array
  • 时间:2012-04-16 19:38:45
  •  标签:
  • php

我有着一种逻辑结构或想法,即想发生的事情,而我希望用阵列将它列入公共卫生和社会福利部。

10 Loops/occurrence of个月

<个月=> 重复<>/strong>

jan => 2
mar => 1
sep => 5
dec => 2

如上所示,在4个不同月的休息室记录中,有10次的休息时间,每个具体月都有一次像月(整整整)重复5次这样的机会。 这一想法与一个人记录其旅行月数以及他从10次记录的旅行中旅行次数相同。 利用Arrays在PHP中如何建立这一系统? 任何建议或答案都受到高度赞赏!

这里的奥基公司实际交易了我想要做的事情,即从一个数据库中提取几个月的记录,然后想显示从数据库中提取的几个月以及重复的多倍,例如,显示的情况如下:

Jan (2)
Sep (5)

I wanted it to be dynamic, no certain month will be displayed if it doesn t exist from the database record.

最佳回答

我认为他试图进行初步的频率分析。 假设你有朝一阵列,你可以使用<strtotime()<>date(<>>>)功能生成钥匙,然后加以平整。

First, create some dummy data:

// dummy data; unsure of the format, so going with time()-like structure
$dates = array();
for( $i = 0; $i < 10; $i++ ) {
    $dates[] = strtotime(sprintf("%s-%s-2012", rand(1,30), rand(1,12) ));
}

现在进行频率计算,关键是每月按日期(“M”......):

$freq = array();
foreach( $dates as $timestamp ) {
    // assuming it s all the same year, discover the month
    $month = date("M", $timestamp );

    if( !isset($freq[$month]) ) $freq[$month] = 0;
    $freq[$month]++;
}

此时此刻,你希望做些什么:

print_r( $freq );

Array
(
    [Sep] => 2
    [Feb] => 2
    [Nov] => 1
    [Dec] => 1
    [Jan] => 2
    [Apr] => 1
    [May] => 1
)

如果该年不同,你可能希望将这种或那种方式合并。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...