English 中文(简体)
PHP阵列问题,阵列——组合——没有解决问题
原标题:PHP array problem, array_merge() does not solve the problem

如何解决阵容问题?

<>>收到结果:

Array
(
    [0] => 2011/03/13
    [1] => 2011/03/14
    [2] => 2011/02/21
)

现在我未能取得以下成果:

Array
(
    [0] => 2011/03/13
)
Array
(
    [0] => 2011/03/14
)
Array
(
    [0] => 2011/02/21
)

<>蓬皮>

<?php
function get_dir_iterative($dir= . ,$exclude=array( cgi-bin , . , .. )){
    $exclude=array_flip($exclude);
    if(!is_dir($dir)){return;}
    $dh=opendir($dir);
    if(!$dh){return;}
    $stack=array($dh);
    $level=0;
    while(count($stack)){
        if(false!==($file=readdir($stack[0]))){
            if(!isset($exclude[$file])){
                if(is_dir("$dir/$file")){
                    $dh=opendir("$file/$dir");
                    if($dh){
                        $d=$file;
                        array_unshift($stack,$dh);
                        ++$level;
                    }
                }else{
                    if(isset($d)&&$level>0){
                        $mod=date( Y/m/d ,filemtime("$d/$file"));
                        $ds="$d/";
                    }else{
                        $mod=date( Y/m/d ,filemtime($file));
                        $ds=  ;
                    }
                    $array=array($mod);
                    //$b=array_merge($array); // it doesn t solve the problem
                    print_r($array);
                }
            }
        }else{
            closedir(array_shift($stack));
            --$level;
        }
    }
}
get_dir_iterative();
?>

Update:
On replacing $array=array($mod); with $array[]=$mod; does not return excepted result.

Array
(
    [0] => 2011/03/13
)
Array
(
    [0] => 2011/03/13
    [1] => 2011/03/14
)
Array
(
    [0] => 2011/03/13
    [1] => 2011/03/14
    [2] => 2011/02/21
)
最佳回答
                $array=array($mod);
                //$b=array_merge($array); // it doesn t solve the problem
                print_r($array);

一个阵列——合并至少需要两个阵列来做事。 你们只提供这种服务,因此没有什么东西可以合并。 你的“生命”版本每次都创造了一个新阵列,因此,你重新获得坏产出。 为什么不干

 $array[] = $mod;

每一胎的阵亡时间是哪里的。 你们可能还要储存档案细节,因此,你知道时间是从哪里来的。

 $array[$dir/$file] = $mod;

可能有更多的用途。

问题回答

array_merge() takes several parameters, the arrays that you want to merge, in your situation it should be:

array_merge($array, $mod);
// Or:
$array[] = $mod;

请注意,你只能给你的全球阵列(第二例)增添新的条目,以增加价值。 Array-merge食比它需要多。

您可以通过替换这一代码:$array=array($mod); with this Code:$array[]=$mod;

以<代码>$b[] = array取代评论。





相关问题
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 ...

热门标签