簡體   English   中英

從數組Laravel PHP獲取數組值

[英]Get Values on array from array Laravel PHP

我在laravel中進行計划任務,我需要知道其他表的值,在這種情況下,我會獲取屬性,后來我從表屬性中的外鍵將句點保存在數組中,以后我需要從在表格周期中的“日期”,但是當我得到日志時,我得到了這個。

[2017-07-21 18:11:50] local.INFO: [{"id":5,"title":"Hola","date":"2017-07-25"}] 
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]

而且我無法使用$ v-> {“ id”},$ v-> id,$ v [“ id”]訪問索引,我不知道這是否是用於保存日期信息的方式,這是我的功能,謝謝。

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {

        $properties = DB::table( 'properties' )->where( 'status', '=', 1 )->whereNotNull( 'id_client' )->whereNotNull( 'id_period' )->get();

        $dates = array();

        foreach ($properties as $k => $v) {
            $dates[$k] = DB::table( 'periods' )->where( 'id', '=', $v->id_period )->whereDate('date', '>', date('Y-m-d'))->get();
        }

        $properties_status = array();

        /* ----- HERE ---------*/
        foreach ($dates as $v) {
            Log::info($v);
        }


    })->everyMinute();
}

您應該使用json_decode($v)以便將其視為結構。 否則對您來說只是一個字符串。

這是JSON。 這是一種數據格式。 您可以使用以下方法在PHP中對其進行解碼:

$var = json_decode($v, true);

$var您將獲得一個普通數組。 您可以使用print_r($var);簡單檢查print_r($var);


手冊

PHP:json_decode

DB::table()->get()返回一個集合,因此可以使用:

Log::info($v->id);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM