title: Calculation per member based on dependents ( Spouse / Childs ) and their employment status and their age
body: <p>i have a dropdown where i can select a user, and then send his id via an ajax call to gather info about him and calculate something called " Family Allowance " , there are rules for this calculation that depend on the <strong>age</strong> of the dependent of the selected user on my system ( either his spouse or his child/children ), and the <strong>employment type</strong> of each dependent ( Not employed / Employed ), the pricing that is based on these parameters is different from a child to a spouse ex:
  a spouse that is unemployed gets a + 50$
  a child that is unemployed and under 18 gets 20$</p>
  
  <p>I was able to do the calculation for 1 child or 1 spouse easily, but with both combined i've hit a wall ( it can be 1 up to 5 children and only 1 spouse ).</p>
  
  <p>I'm pulling the dependent types( Spouse / Child ), employment types ( Employed / Unemployed), and age  in a GROUP_CONCAT each one.</p>
  
  <p><a href="https://i.stack.imgur.com/YlfE0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YlfE0.png" alt="enter image description here"></a></p>
  
  <p>My goal is to loop on all the dependents, put conditions on each one's age and employment type and increment the allowance amount accordingly, i'll be trying to do nested foreachs but i'm not sure how to manage it</p>
  
  <p>here is my current code ( Everything above  <code>if ($CAT=="Child,Spouse")</code> is working fine ): </p>
  
  <pre><code> if( strpos($CAT, $searchString) != false ) {
  
          $category = explode( ',', $CAT);
  
  
      } else {     $category=$CAT;   
  
      }
  
  
  if( strpos($EMPTYPE, $searchString) != false ) {
  
          $EMPTYPE = explode( ',', $EMPTYPE);
  
  
      } else {     $EMPTYPE=$EMPTYPE;   
  
      }
  
      if ($category=="Child"){
  
          if( strpos($DOBS, $searchString) != false ) {
  
  $DOBS = explode( ',', $DOBS);
  $from = new DateTime($DOBS);
  $to   = new DateTime('today');
  $dep_Age=$from-&gt;diff($to)-&gt;y;
  } else {
  $from = new DateTime($DOBS);
  $to   = new DateTime('today');
  $dep_Age=$from-&gt;diff($to)-&gt;y;
  
  if ($dep_Age&lt;18) { $familyAllowance=33000; }
    if ($dep_Age&lt;25 &amp;&amp; $EMPTYPE=="NotEmployed") { $familyAllowance=33000; }
    if ($dep_Age&gt;25 &amp;&amp; $EMPTYPE=="NotEmployed") { $familyAllowance=0; }
    if ($dep_Age&gt;18 &amp;&amp; $EMPTYPE=="FullTime") { $familyAllowance=0; }
  
  }
  
          // $familyAllowance=33000;
  
      } else if ($category=="Spouse"){
  if ($EMPTYPE=="NotEmployed") { $familyAllowance=60000; } else {  $familyAllowance=0; }
  
      }
      else  if ($CAT=="Child,Spouse"){ 
  
  
  
  
  $EMPTYPE=implode( ',', $EMPTYPE);
  if ($empArray="NotEmployed,NotEmployed") { $familyAllowance=60000+60000; }
  
  
      // $familyAllowance=60000+33000;
      } // end Child,Spouse
  </code></pre>