You can generate variable names in for loops like this.
Just change the value of $how_many_i_want
.
$how_many_i_want = 3;
for($x=0;$x<$how_many_i_want;$x++){
generate_entropy($x);
}
function generate_entropy($nth){
$kriteria = ['C1','C2','C3','C4','C5','C6'];
$alternatif = ['ALT1','ALT2','ALT','ALT4','ALT5','ALT6','ALT7'];
${"nEntropy$nth"} = array();
for ($i=0;$i<count($kriteria);$i++){
for ($j=0;$j<count($alternatif);$j++){
${"nEntropy$nth"}[$i] = (((-1)/log(7)) *(
($probabilitas[0][$nth]*log($probabilitas[0][$nth]))+
($probabilitas[1][$nth]*log($probabilitas[1][$nth]))+
($probabilitas[2][$nth]*log($probabilitas[2][$nth]))+
($probabilitas[3][$nth]*log($probabilitas[3][$nth]))+
($probabilitas[4][$nth]*log($probabilitas[4][$nth]))+
($probabilitas[5][$nth]*log($probabilitas[5][$nth]))+
($probabilitas[6][$nth]*log($probabilitas[6][$nth]))
));
}
}
showb(${"nEntropy$nth"});
}
6
solved How to make dynamic array from static array