String Concatenation in PHP from Array

-1

I have a query to my database that returns to me an array every row of the database is an array,

$qr = DBRead('sales', "WHERE status = 1");
foreach ($qr as $position => $linha){
    $vendas = $linha['cod_produto'];

    var_dump($vendas); 
}

This print for the sequential array

array (size=25)
    'venda' => string '96' (length=2)
    'cod_produto' => string '1; 2; 8' (length=7)

array (size=25)
    'venda' => string '98' (length=2)
    'cod_produto' => string '; 1; 2; 8' (length=9)

And so on, the more you record more arrays.

My question is I want to get the key cod_produto and select its value and put it in a single string with all those concatenated values does anyone have an idea how to do this with php?     

asked by anonymous 03.02.2017 / 02:53

1 answer

0

To concatenate string in php you should use $vartexto = $vartexto . 'texto novo'; or reduced form $vartexto.='texto novo';

Follow your code snippet with a $cod_produtos_juntos variable that will do this concatenation for you:

$qr = DBRead('sales', "WHERE status = 1");

$cod_produtos_juntos = '';
foreach ($qr as $position => $linha)
{
    $cod_produtos_juntos.=$linha['cod_produto'];
}

echo $cod_produtos_juntos;
    
03.02.2017 / 12:19