带密钥的foreach问题

时间:2016-09-13 14:18:37

标签: php foreach

我需要从我的foreach中提取一些数据但是没办法。

这是我的foreach

$res = $pdo->getLesProduits();
$data = array( 'res'=> array());
foreach ($res as $key => $value) {
    $data['res'][$key] =  $value;
}

这是我的查询

public function getLesProduits(){
$req = "select * from produit";
$res = PdoGR::$monPdo->query($req);
$lesLignes = $res->fetchAll(PDO::FETCH_ASSOC);
return $lesLignes;
}

这是var_dump($ data)

var_dump($data)

但我需要,例如,获取所有'参考'或所有'指定',但当我执行此时:

echo $res['designation'];

我只看到一行......

更新:

if(isset($_POST['referenceProduit'])){
    $res = $pdo->getLesProduits();
    $data = array( 'res'=> array());
    foreach ($res as $key => $value) {
        //$data['res'][$key] =  $value;
        $designations = array_column($res['res'], 'designation');
        $unique_designations = array_unique(array_column($res['res'], 'designation'));
        $designations = array_values(array_filter($array['res'], function($a) use($_POST['referenceProduit']){
        return $a['reference'] == $reference;}))[0];
    }
    $data['produit'] =  '       
        <label for="designation" class="col-sm-1 control-label">Désignation</label>
        <div class="col-sm-3">
            <input type="text" class="form-control" name="designation" id="designation" value="'. $a['reference'] .'" readonly>
        </div>
        <label for="prix" class="col-sm-1 control-label">Prix </label>
        <div class="input-group col-sm-1">
            <input type="text" class="form-control" aria-describedby="basic-addon2" name="prix" id="prix" value="'. $value['prix'] .'" readonly>
            <span class="input-group-addon" id="basic-addon2">€</span>
        </div>
        ';
}

0 个答案:

没有答案