Laravel Convert the value of an array to Int

-1

Good, I need to save in a variable the specific value of an array in another variable

From here I receive the data:

 $data = \DB::select("
            SELECT 
                SUM(CASE WHEN status like 'Por Despachar' THEN 1 ELSE 0 END) AS Por_Despachar
                ,SUM(CASE WHEN status like 'Planificado' THEN 1 ELSE 0 END) AS Planificado
                ,SUM(CASE WHEN status like 'Despachado' THEN 1 ELSE 0 END) AS Despachado
            FROM presupuesto
        ");
Obtengo 3 valores por cada condicion
Quiero guardar el valor De planificado en otra variable es solo eso
$dta = [];
foreach($data as $d) {array_push($dta, $d);}

I get this:

array:1 [▼
0 => {#330 ▼
+"por_despachar": "4"
+"planificado": "1"
+"despachado": "0"
}
]

I need something like that

$intval1 = dta[1]; <--- guardar el valor especifico deacuerdo al indice

but I get this Error:

Undefined offset: 1

example then if dta [1] has a value of 5 and I show on screen $ intval1 should show:

5
    
asked by Jorge Ortiz 16.06.2017 в 03:34
source

1 answer

0

If I understood the problem well, what you need is to specify the corresponding key:

foreach ($data as $d) {
    array_push($dta, $d['planificado']);
}

Viewing your query to the database, I do not understand why use a foreach() if you are getting some sums, for which I do not think you are generating several records in $data .

    
answered by 16.06.2017 в 04:02