从数组

时间:2018-01-24 07:22:55

标签: php mysql arrays

所以,我想从这个阵列中选择每个项目的项目 [" A185"," A740"," A540"] 比如我想选择

  

$ cie [0] = A185 A740

     

类似 $ cie [0] = A185

这是我的代码到目前为止,因为我从MySQL表中的一行中获取该代码。

while ($row = pg_fetch_array($resul)) {
    $cie10 = array($row["cie"]);
}


    $cie = ["A185","A740"];

    $values = array_count_values($cie);

    $top = array_slice($values, 0, 1);
    print_r($top);

我得到了什么: 数组([[" A185"," A740"," A540"]] => 1)

它只是赢了工作。

2 个答案:

答案 0 :(得分:0)

如果我理解你的问题。您正在寻找: -

$Fullarray = ["A185","A740","A540"];
$cie = array_slice($Fullarray,0,2);
foreach ($cie as $name) {
   $d[] = '"' . $name . '"';
}
$implodekeys = "[".implode(',',$d)."]";
$newarray[$implodekeys] =1;
echo "<pre>"; print_r($newarray);

希望它有所帮助!

答案 1 :(得分:0)

我确定您要显示数组变量中的数据

$var = ["A185","A740","A540"]; // Asume as you stored the values in the array called var

foreach($var as $x){
 print_r($x);
 echo "<br/>";
}

编辑:突出显示代码