Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Operacja na tablach, problem z pętlą for
pela222
post 10.07.2020, 09:43:30
Post #1





Grupa: Zarejestrowani
Postów: 85
Pomógł: 0
Dołączył: 17.04.2013

Ostrzeżenie: (0%)
-----


Tutaj moja tabela wyjściowa.
  1. <?php
  2. $policies =
  3. 'TerLifIns' =>
  4. 0 =>
  5. 'company' => 'NIA',
  6. 'type' => 'Term Life Insurance',
  7. 'no' => '67845678',
  8. 'issueDate' => '2016-09-10',
  9. 'used' => 'yes',
  10. 'group' => 'Group',
  11. 'owner' => 'OWNER',
  12. 'premium' => '55',
  13. 'paymentFrequency' => 'miesięcznie',
  14. 'coverBasis' => 'Dual Life',
  15. 'lifeInsured' => 'Chester Tester, Mary Testerowa',
  16. 'indexation' => 'Yes',
  17. 'term' => '15',
  18. 'seriousIllness' => 'Standalone',
  19. 'conversion' => 'Yes',
  20. 'lifeCoverMark' => 170,
  21. 'seriousIllnessMark' => 70,
  22. 'hospitalCoverMark' => 161,
  23. 'accidentCoverMark' => 201,
  24. 'surgeryMark' => 1,
  25. 'fractureMark' => 1,
  26. 'lifecoverBasisMark' => 0,
  27. 'primary' =>
  28. 'lifeCover' => '85,000',
  29. 'seriousIllness' => '35,000',
  30. 'cancerCover' => '0',
  31. 'hospitalCover' => '80',
  32. 'accidentCover' => '100',
  33. 'fracture' => 'Yes',
  34. 'surgery' => 'Yes',
  35. ),
  36. 'secondary' =>
  37. 'lifeCover' => '85,001',
  38. 'seriousIllness' => '35,001',
  39. 'cancerCover' => '0',
  40. 'hospitalCover' => '81',
  41. 'accidentCover' => '101',
  42. 'fracture' => 'Yes',
  43. 'surgery' => 'No',
  44. ),
  45. 'DOC' =>
  46. 'sictypedis' => 'Opis sictypedis dla NIA.',
  47. 'lifedis' => 'Opis life dla NIA.',
  48. 'sicdis' => 'Opis sic dla NIA.',
  49. 'hospitaldis' => 'Opis hospital dla NIA.',
  50. 'accidentdis' => 'Opis acc dla NIA.',
  51. 'surgerydis' => 'Opis surg dla NIA.',
  52. 'fracturedis' => 'Opis fra dla NIA.',
  53. 'indexationdis' => 'Opis index dla NIA.',
  54. 'conversiondis' => 'Opis conver dla NIA.',
  55. 'companydis' =>
  56. 0 => 'Opis 0 dla NIA.',
  57. 1 => 'Opis 1 dla NIA.',
  58. 2 => 'Opis 2 dla NIA.',
  59. ),
  60. 'companyaddress' =>
  61. 'name' => 'NIA ',
  62. 'street' => 'street NIA',
  63. 'area' => 'area NIA',
  64. 'county' => 'county NIA',
  65. 'zipcode' => 'zip NIA',
  66. ),
  67. 'otherdefault' => 'x',
  68. ),
  69. ),
  70. 1 =>
  71. 'company' => 'IL',
  72. 'type' => 'Term Life Insurance',
  73. 'no' => '12345678',
  74. 'issueDate' => '2016-09-10',
  75. 'used' => 'yes',
  76. 'group' => 'Group',
  77. 'owner' => 'OWNER',
  78. 'premium' => '25',
  79. 'paymentFrequency' => 'miesięcznie',
  80. 'coverBasis' => 'Dual Life',
  81. 'lifeInsured' => 'Chester Tester, Mary Testerowa',
  82. 'indexation' => 'Yes',
  83. 'term' => '23',
  84. 'seriousIllness' => 'Accelerated',
  85. 'conversion' => 'Yes',
  86. 'lifeCoverMark' => 400,
  87. 'seriousIllnessMark' => 200,
  88. 'hospitalCoverMark' => 201,
  89. 'accidentCoverMark' => 241,
  90. 'surgeryMark' => 0,
  91. 'fractureMark' => 0,
  92. 'lifecoverBasisMark' => 0,
  93. 'primary' =>
  94. 'lifeCover' => '200,000',
  95. 'seriousIllness' => '100,000',
  96. 'cancerCover' => '0',
  97. 'hospitalCover' => '100',
  98. 'accidentCover' => '120',
  99. 'fracture' => '',
  100. 'surgery' => '',
  101. ),
  102. 'secondary' =>
  103. 'lifeCover' => '200,001',
  104. 'seriousIllness' => '100,001',
  105. 'cancerCover' => '0',
  106. 'hospitalCover' => '101',
  107. 'accidentCover' => '121',
  108. 'fracture' => '',
  109. 'surgery' => '',
  110. ),
  111. 'DOC' =>
  112. 'sictypedis' => 'Opis sictypedis dla IL.',
  113. 'lifedis' => 'Opis life dla IL.',
  114. 'sicdis' => 'Opis sic dla IL.',
  115. 'hospitaldis' => 'Opis hospital dla IL.',
  116. 'accidentdis' => 'Opis acc dla IL.',
  117. 'surgerydis' => 'Opis surg dla IL.',
  118. 'fracturedis' => 'Opis fra dla IL.',
  119. 'indexationdis' => 'Opis index dla IL.',
  120. 'conversiondis' => 'Opis conver dla IL.',
  121. 'companydis' =>
  122. 0 => 'Opis 0 dla IL.',
  123. 1 => 'Opis 1 dla IL.',
  124. 2 => 'Opis 2 dla IL.',
  125. ),
  126. 'companyaddress' =>
  127. 'name' => 'IL ',
  128. 'street' => 'street IL',
  129. 'area' => 'area IL',
  130. 'county' => 'county IL',
  131. 'zipcode' => 'zip IL',
  132. ),
  133. 'otherdefault' => 'x',
  134. ),
  135. ),
  136. ),
  137. 'MorIns' =>
  138. ),
  139. 'WOL' =>
  140. ),
  141. 'IncIns' =>
  142. ),
  143. 'AccSicAndHos' =>
  144. ),
  145. 'MedCas' =>
  146. ),
  147. 'PerAcc' =>
  148. ),
  149. 'SovIncAssPla' =>
  150. )
  151. );
  152. // echo ('<pre>');
  153. // print_r($policies);
  154. // echo ('</pre>');
  155. ?>


Na podstawie tej tabli tworze kolejną jak poniżej.
  1. function getRecomendationTerLifInsData($policies) {
  2. $recomend = array();
  3.  
  4. //listuj wszystkie discription dla wszystkich typów i wszystkich polisy
  5. foreach ($policies as $type => &$policieType) {
  6. if($type == 'TerLifIns') {
  7. $count = count($policieType);
  8. foreach ($policieType as &$policie) {
  9. for($n=0; $n<$count; $n++){
  10. if($policie['lifeCoverMark']){$recomend[] = array('Kwota dla primary to €'.$policies['TerLifIns'][$n]['primary']['lifeCover'].', natomiast kwota dla drugiego ubezpieczonego to €'.$policies['TerLifIns'][$n]['secondary']['lifeCover'].'');}
  11. if($policie['seriousIllnessMark']){$recomend[] = array('SIC dla pierwszego to €'.$policies['TerLifIns'][$n]['primary']['seriousIllness'].', natomiast suma SIC dla drugiego to €'.$policies['TerLifIns'][$n]['secondary']['seriousIllness'].' na okres '.$policies['TerLifIns'][$n]['term'].' lat.'.$policies['TerLifIns'][$n]['DOC']['sictypedis'].'');}
  12. if($policie['hospitalCoverMark']){$recomend[] = array('Szpital dla pierwszego to €'.$policies['TerLifIns'][$n]['primary']['hospitalCover'].' za dzień pobytu dla pierwszego, a dla drugego €'.$policies['TerLifIns'][$n]['secondary']['hospitalCover'].'');}
  13. if($policie['accidentCoverMark']){$recomend[] = array('Acc dla pierwszego to €'.$policies['TerLifIns'][$n]['primary']['accidentCover'].' a dla drugiego Acc to €'.$policies['TerLifIns'][$n]['secondary']['accidentCover'].'');}
  14. if($policie['surgeryMark']){$recomend[] = array('Sur opis. '.$policies['TerLifIns'][$n]['DOC']['surgerydis'].'');}
  15. }
  16. // $recomend[] = array('----');
  17. // foreach ($policie['DOC'] as $value) {
  18. // if(!is_array($value)){
  19. // $recomend[] = array($value);
  20. // }
  21. // }
  22. // foreach ($policie['DOC']['companydis'] as $value) {
  23. // $recomend[] = array($value);
  24. // }
  25. // $recomend[] = array('----'); // spacer for statement of suitability
  26. }
  27. }
  28. }
  29. return $recomend;
  30. }
  31.  
  32. $output = getRecomendationTerLifInsData($policies);
  33. echo ('<pre>');
  34. print_r($output);
  35. echo ('</pre>');


Problem z jakim nie wiem jak sobie poradzić to niepotrzebne wyświetlenie jednej z pętli.


Nie wiem czy jest to widoczne ale chodzi o niepotrzebne wywołanie tej pętli
  1. foreach ($policieType as &$policie) {
  2. for($n=0; $n<$count; $n++){

Nie wiem jak to prawidłowo zapisać.
Dziękuję tradycyjnie za wyrozumiałość i pomoc.

Ten post edytował pela222 10.07.2020, 09:54:40
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 02:52