前提・実現したいこと
初心者です。初歩的な質問ですが調べてもよく分からなかったので質問させてください。
現在PHPの練習として以下の問題を解いているのですが、
0以外の整数のみ配列に格納するにはどうすればいいのでしょうか、、?
Q.
入力された値から、各硬貨・紙幣の枚数を配列に格納する。
配列の内容は、硬貨・紙幣の金額をKeyにして枚数を値にする。
枚数が0枚のものは、配列に格納しない。
また、配列には金額の小さいものから順に並んでいる必要がある。
発生している問題・エラーメッセージ
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 10000 => 99
- 10000 => 99.0
- 1 => 0
- 5 => 0.0
- 10 => 0.0
- 50 => 0.0
- 100 => 0.0
- 500 => 0.0
- 1000 => 0.0
- 5000 => 0.0
)
該当のソースコード
php
1public function getBillCount(int $bill): ?array 2 { 3 $count_1 = $bill%5; 4 $count_5 = floor(($bill%10)/5); 5 $count_10 = floor(($bill%50)/10); 6 $count_50 = floor(($bill%100)/50); 7 $count_100 = floor(($bill%500)/100); 8 $count_500 = floor(($bill%1000)/500); 9 $count_1000 = floor(($bill%5000)/1000); 10 $count_5000 = floor(($bill%10000)/5000); 11 $count_10000 = floor($bill/10000); 12 13 $num = array ( 14 "1" => $count_1, 15 "5" => $count_5, 16 "10" => $count_10, 17 "50" => $count_50, 18 "100" => $count_100, 19 "500" => $count_500, 20 "1000" => $count_1000, 21 "5000" => $count_5000, 22 "10000" => $count_10000, 23 ); 24 25 return $num; 26 } 27 28 public function testGetBillCount_0枚有り() 29 { 30 if ($count_1=$count_5=$count_10=$count_50=$count_100=$count_500=$count_1000=$count_5000=$count_10000 !== 0) { 31 $num = array ( 32 "1" => $count_1, 33 "5" => $count_5, 34 "10" => $count_10, 35 "50" => $count_50, 36 "100" => $count_100, 37 "500" => $count_500, 38 "1000" => $count_1000, 39 "5000" => $count_5000, 40 "10000" => $count_10000, 41 ); 42 } 43
現在if文で**「0じゃないとき、格納する」**という意味合いで
このようなコードを書いています。
どうかご回答よろしくお願いします!!