数组键的动态变量

时间:2014-10-11 19:20:16

标签: php arrays

我有一个多维数组,它计算每个可能的数组组合的概率'元素。但我需要将每个概率存储在一个变量中。

    $array_for_19=[
["A 1","A 1","A 1", "A 2","A 3","A 2","A 1","A 3", "A 2", "A 1","A 3", "A 3", "A 2","A 1", "A 2"],
["A a","A a","A c", "A b","A c","A c","A c","A a", "A a", "A c","A c", "A a", "A a","A a", "A c"],
["1 a","1 b","1 a", "1 a","1 b","1 c","1 b","1 c", "1 b", "1 a","1 a", "1 c", "1 b","1 a", "1 a"],
["2 a","2 a","2 a", "2 a","2 a","2 a","2 a","2 b", "2 b", "2 a","2 a", "2 b", "2 a","2 b", "2 b"],
["3 b","3 c","3 b", "3 c","3 a","3 b","3 c","3 b", "3 b", "3 b","3 c", "3 c", "3 a","3 c", "3 b"]];
function algorithms19_20($array){
    for ($i=0;$i<count($array);$i++){
        $newarray=[];
        for($j=0;$j<count($array[$i]);$j++){
            $splitted=split(" ", $array[$i][$j]);
                array_count_values($array[$i]);
            array_push($newarray, $splitted);   

        }
        $keycount1;
        foreach (array_count_values($array[$i]) as $key => $value) {
                $keycount1++;
                $probabilty=round(($value/count($array[$i])),2);
                echo "$key - <strong>$value</strong> <br/>Probability: $probabilty<br/>"; 
                ${(string)$key}=$probabililty;
                echo $A1;
        }
        echo "<br/>";
    }
}

但我理解,我的关键是#34; A 1&#34;,所以变量不能像$ A那样被调用1.那么我怎样才能做到这一点呢?

0 个答案:

没有答案