Should I store the result of an function into an array?

前端 未结 2 1735
时光说笑
时光说笑 2021-01-23 17:03

I have a function like this:

function time_elapsed_string($ptime)
{
            $date_time = strtotime(\"1348-10-10 04:30:01\") + $ptime;
            $year = dat         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-23 17:13

    This is a no brainer.

    Yes - store the function call result of time_elapsed_string($ptime) in an array, then use that to access your results. You're wasting CPU cycles otherwise!

    // call it once
    $result = time_elapsed_string($ptime);
    
    // then use:
    $result['date'];
    $result['time'];
    $result['difference'];
    

提交回复
热议问题