Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数组中除法返回?_Php - Fatal编程技术网

Php 从数组中除法返回?

Php 从数组中除法返回?,php,Php,我得到了一个数组,它将数据输出到xml中。看起来是这样的: $data = array( 'trip_id' => $this->trip_id, 'from' => $this->from, 'from_lat' => $this->from_lat, 'from_lon' => $this->

我得到了一个数组,它将数据输出到xml中。看起来是这样的:

        $data = array(
            'trip_id'      => $this->trip_id,
            'from'         => $this->from,
            'from_lat'     => $this->from_lat,
            'from_lon'     => $this->from_lon,
            'to'           => $this->to,
            'to_lat'       => $this->to_lat,
            'to_lon'       => $this->to_lon,
            'when'         => $this->when,
            'when_iso'     => date('Y-m-d H:i', $this->when),
            'details'      => $this->details,
            'got_car'      => $this->got_car,
            'inserted'     => $this->inserted,
            'name'         => $this->name,
            'email'        => $this->email,
            'phone'        => $this->phone,
        );
$this_when包含一个unix时间戳,我想添加一个新的时间类型which is when_rel,它应该包含unix时间戳所指的从今天开始的天数。1、2等

我不想知道如何将数学应用于从数组中获取的值。我尝试了这个,但它只是指出了一个错误:

            'when_rel'     => ($this->when/60);

你有没有试过“when_rel”=>$this->when/60?

你有没有试过“when_rel”=>$this->when/60?

就像你在iso:

'when_rel'     => date('d', $this->when),

还有什么错误?

就像您在iso:

'when_rel'     => date('d', $this->when),

还有什么错误?

是因为你弄乱了数组的右括号吗?我刚刚举了一个例子,在正常情况下,这样的划分应该很好:

<?php 

class Foo {
    public $num;

    public function  __construct() {
        $this->num = 234534253454;
    }
}

$foo = new Foo;
$arr = array('hello' => ($foo->num / 60), 'blah' => 'foo');
print_r($arr);
?>

演示:

是因为你弄乱了数组的右括号吗?我刚刚举了一个例子,在正常情况下,这样的划分应该很好:

<?php 

class Foo {
    public $num;

    public function  __construct() {
        $this->num = 234534253454;
    }
}

$foo = new Foo;
$arr = array('hello' => ($foo->num / 60), 'blah' => 'foo');
print_r($arr);
?>

演示:

非常感谢您的测试,正如格罗斯沃格尔指出的,这里有一个分号而不是一个,occram再次证明是正确的

非常感谢您的测试,正如格罗斯沃格尔所指出的,这里有一个分号而不是一个,occram再次证明是正确的

请用更合适的代码片段更新您的问题,上面的所有内容显然没有意义,是完全重写了语法错误,希望这对您有所帮助!谢谢,最后一切都有意义了,还有,返回的错误是什么?应该可以正常工作。这是什么->什么时候?请发布var_dump$this->when的结果。如果您遇到错误,请也发布这些错误。您测试的代码在数组定义中真的有分号吗?当然,它应该是一个逗号。请用更合适的代码片段更新您的问题,上面的所有内容显然没有意义,是语法错误完全重写了,希望这对您有所帮助!谢谢,最后一切都有意义了,还有,返回的错误是什么?应该可以正常工作。这是什么->什么时候?请发布var_dump$this->when的结果。如果您遇到错误,请也发布这些错误。您测试的代码在数组定义中真的有分号吗?当然,它应该是一个逗号。