Last active
January 30, 2018 13:57
-
-
Save bangiqi/d883220a6afb71025f44faf613ec6a6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = []; | |
$data = [ | |
[ | |
"title"=>"PKS", | |
"total"=>100 | |
], | |
[ | |
"title"=>"Gerinda", | |
"total"=>30 | |
] | |
]; | |
foreach($data as $value){ | |
$arraysum[] = $value["total"]; | |
} | |
$hasilarraysum = array_sum($arraysum); | |
foreach($data as $value){ | |
$hasil = $value["total"]/$hasilarraysum*100; | |
$hasilFormat = number_format($hasil); | |
echo "persentase partai ".$value["title"].": ".$hasilFormat."% <br>"; | |
} | |
echo "<br>ini contoh lainnya <br>"; | |
$jumCowok = 5; | |
$jumCewek = 7; | |
$total = $jumCowok + $jumCewek; | |
// menghitung prosentase laki-laki dan perempuan | |
$prosenCowok = $jumCowok/$total * 100; | |
$prosenCewek = $jumCewek/$total * 100; | |
$angka_cowok = number_format($prosenCowok); | |
$angka_cewek = number_format($prosenCewek); | |
echo "jumlah laki-laki : ".$angka_cowok."%<br>"; | |
echo "jumlah perempuan : ".$angka_cewek."%<br>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment