Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Operacja na tablach, problem z pętlą for
pela222
post
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
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




private function getRecomendationTerLifInsData($documentData['policies']['TerLifIns']) {
W definicji funckji okresla sie nazwe parametru a nie jakas sciezke w tablicy
Go to the top of the page
+Quote Post
pela222
post
Post #3





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

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


Cytat(nospor @ 13.07.2020, 10:36:07 ) *
private function getRecomendationTerLifInsData($documentData['policies']['TerLifIns']) {
W definicji funckji okresla sie nazwe parametru a nie jakas sciezke w tablicy

Ja się cały czas uczę, codziennie się uczę - (cytując pewnego Pana z telewizji (IMG:style_emoticons/default/smile.gif) )

  1. //Rekomendacja Term Life
  2. private function getRecomendationTerLifInsData($documentData) {
  3. $TerLifIns = $documentData['policies']['TerLifIns'];
  4. $recomend = array();
  5. $count = count($TerLifIns);
  6. for($n=0; $n<$count; $n++){
  7. if($TerLifIns[$n]['coverBasis'] == 'Dual Life' || $TerLifIns[$n]['coverBasis'] == 'Joint Life') {
  8. if($TerLifIns[$n]['lifeCoverMark']){
  9. $recomend[] = array('Utraty życia, gdzie suma ubezpieczenia jaką rekomenduje dla pierwszego ubezpieczonego ('.$documentData['primary']['firstName'].' '.$documentData['primary']['lastName'].') to ?'.$TerLifIns[$n]['primary']['lifeCover'].', natomiast suma ubezpieczenia jaką rekomenduje dla drugiego ubezpieczonego ('.$documentData['secondary']['firstName'].' '.$documentData['secondary']['lastName'].') to ?'.$TerLifIns[$n]['secondary']['lifeCover'].' na okres '.$TerLifIns[$n]['term'].' lat.');
  10. }
  11. if($TerLifIns[$n]['seriousIllnessMark']){
  12. $recomend[] = array('Poważnej choroby, gdzie rekomendowana kwota ubezpieczenia dla pierwszego ubezpieczonego ('.$documentData['primary']['firstName'].' '.$documentData['primary']['lastName'].') to ?'.$documentData['policies']['TerLifIns']['0']['primary']['seriousIllness'].', natomiast suma ubezpieczenia jaką rekomenduje dla drugiego ubezpieczonego ('.$documentData['secondary']['firstName'].' '.$documentData['secondary']['lastName'].') to ?'.$documentData['policies']['TerLifIns']['0']['secondary']['seriousIllness'].' na okres '.$documentData['policies']['TerLifIns']['0']['term'].' lat.'.$documentData['policies']['TerLifIns']['0']['DOC']['sictypedis'].'');
  13. }
  14. if($TerLifIns[$n]['hospitalCoverMark']){
  15. $recomend[] = array('Pobytu w szpitalu, kwota ubezpieczenia to ?'.$documentData['policies']['TerLifIns']['0']['primary']['hospitalCover'].' za dzień pobytu dla '.$documentData['primary']['firstName'].' oraz ?'.$documentData['policies']['TerLifIns']['0']['secondary']['hospitalCover'].' za dzień pobytu dla '.$documentData['secondary']['firstName'].'.'.$documentData['policies']['TerLifIns']['0']['DOC']['hospitaldis'].'');
  16. }
  17. if($TerLifIns[$n]['accidentCoverMark']){
  18. $recomend[] = array('Niezdolności do pracy w skutek wypadku, kwota ubezpieczenia to ?'.$documentData['policies']['TerLifIns']['0']['primary']['accidentCover'].' za tydzień niezdolności dla '.$documentData['primary']['firstName'].' oraz ?'.$documentData['policies']['TerLifIns']['0']['secondary']['accidentCover'].' za tydzień niezdolności dla '.$documentData['secondary']['firstName'].'. '.$documentData['policies']['TerLifIns']['0']['DOC']['accidentdis'].'');
  19. }
  20. if($TerLifIns[$n]['surgeryMark']){
  21. $recomend[] = array('Ubezpieczenie zabiegów chirurgicznych dla '.$documentData['primary']['firstName'].' oraz dla '.$documentData['secondary']['firstName'].'. '.$documentData['policies']['TerLifIns']['0']['DOC']['surgerydis'].'');
  22. }
  23.  
  24. foreach ($TerLifIns[$n]['DOC'] as $value) {
  25. if(!is_array($value)){
  26. $recomend[] = array($value);
  27. }
  28. }
  29. foreach ($TerLifIns[$n]['DOC']['companydis'] as $value) {
  30. if(!is_array($value)){
  31. $recomend[] = array($value);
  32. }
  33. }
  34. $recomend[] = array('----'); // spacer for statement of suitability
  35.  
  36. }
  37. else {
  38. if($TerLifIns[$n]['lifeCoverMark']){
  39. $recomend[] = array('Utraty życia, gdzie rekomendowana suma ubezpieczenia to ?'.$TerLifIns[$n]['primary']['lifeCover'].' na okres '.$TerLifIns[$n]['term'].' lat.');
  40. }
  41. if($TerLifIns[$n]['seriousIllnessMark']){
  42. $recomend[] = array('Poważnej choroby, gdzie rekomendowana kwota ubezpieczenia to ?'.$TerLifIns[$n]['primary']['seriousIllness'].' na okres '.$TerLifIns[$n]['term'].' lat.');
  43. }
  44. if($TerLifIns[$n]['hospitalCoverMark']){
  45. $recomend[] = array('Pobytu w szpitalu, kwota ubezpieczenia to ?'.$TerLifIns[$n]['primary']['hospitalCover'].' za dzień pobytu.');
  46. }
  47. if($TerLifIns[$n]['accidentCoverMark']){
  48. $recomend[] = array('Niezdolności do pracy w skutek wypadku, kwota ubezpieczenia to ?'.$TerLifIns[$n]['primary']['accidentCover'].' za tydzień niezdolności. '.$TerLifIns[$n]['DOC']['accidentdis'].'');
  49. }
  50.  
  51. foreach ($TerLifIns[$n]['DOC'] as $value) {
  52. if(!is_array($value)){
  53. $recomend[] = array($value);
  54. }
  55. }
  56. foreach ($TerLifIns[$n]['DOC']['companydis'] as $value) {
  57. if(!is_array($value)){
  58. $recomend[] = array($value);
  59. }
  60. }
  61. $recomend[] = array('----'); // spacer for statement of suitability
  62. }
  63. }
  64. return $recomend;
  65. }


Czy to miało by sens? W sensie działa, ale jak macie jakieś uwagi, które pozwolą mi na lepsze zrobienie tego tutaj po to, żeby pójść krok do przodu w mojej nauce, to będę wdzięczny.

PS. Czy jest taka forma zadawania pytań na forum, że zakładam wątek dla projektu, w którym mógłbym Was prosić o podpowiedzi. Czy po prostu przy następnym pytaniu / problemie powinienem zakładać nowy wątek? Tak jak pisałem wcześniej. Mam napisaną API które używam w mojej pracy. Projekt używam sam i sam go rozwijam / modyfikuję. Przy okazji uczę się / staram się uczyć programowania php na nim...Pewnie nie najlepszy sposób bo duże braki podstaw powodują że zadaje frustrujące pytania. Z drugiej strony mam tego świadomość i jak jest czas to wracam / czytam podstawy. Dziękuję za informację.

Ten post edytował pela222 13.07.2020, 13:12:00
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 Aktualny czas: 12.10.2025 - 05:54