Curiosity: does the one-dimensional array become Boolean after traversing?

problem description

I wonder why an one-dimensional array becomes Boolean after experiencing walk. Ask the boss who knows to help solve the doubt.

related codes

public function test(){
        $arr = ["20181102","20181103","20181104","20181105","20181106","20181107"];
        $arr = array_walk($arr,function($item){
            $item = date_format(date_create($item),"m-d");
        });
        var_dump($arr);
        exit;
    }

in fact, what I expect is that the date is formatted as "month-day".

Oct.28,2021

look at the document: PHP: array_walk

function prototype: bool array_walk (array & $array, callable $callback [, mixed $userdata = NULL])
it returns a Boolean.

not to mention the return value is very clear,

returns TRUE, on success or FALSE on failure.

print your date_create ($item)


$arr has been re-assigned by you, and you don't need to use $arr to receive the return value when using array_walk.

Menu