title: CakePHP - How To Iterate an Array and Compare Array Values With a Variable
body: <p>I have this array from <code>$Infor = $this-&gt;StudentFeeUtil-&gt;getPaymentPlanDetails($currentSessionID); pr($Infor)</code></p>
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [PaymentPlan] =&gt; Array
              (
                  [id] =&gt; 16
                  [payment_plan] =&gt; 35
                  [submission_date] =&gt; 2022-11-30
                  [intake_id] =&gt; 1263
                  [session_id] =&gt; 1019
              )
  
      )
  
  [1] =&gt; Array
      (
          [PaymentPlan] =&gt; Array
              (
                  [id] =&gt; 15
                  [payment_plan] =&gt; 35
                  [submission_date] =&gt; 2022-10-31
                  [intake_id] =&gt; 1263
                  [session_id] =&gt; 1019
              )
  
      )
  
  [2] =&gt; Array
      (
          [PaymentPlan] =&gt; Array
              (
                  [id] =&gt; 14
                  [payment_plan] =&gt; 30
                  [submission_date] =&gt; 2022-09-30
                  [intake_id] =&gt; 1263
                  [session_id] =&gt; 1019
              )
  
      )
    )
  </code></pre>
  <p>I would like to iterate through this array and compare the <code>submission_date</code> with the current date <code>$now = new DateTime();</code>. If current date, <code>$now</code> is less than or equal to <code>$submission_date</code> and <code>$currentBalance</code> is greater than 0, then do something. Basically, I want something like this:</p>
  <pre><code>// Check if student has balance
          if ($now &lt;= $Infor[0]['PaymentPlan']['submission_date'] &amp;&amp; $currentBalance &gt; 0) {
              // Do something
              echo &quot; Tell student to pay up balance!&quot;;
          } else if ($now &lt;= $Infor[1]['PaymentPlan']['submission_date'] &amp;&amp; $currentBalance &gt; 0){
              // Do something 
              echo &quot; Tell student to pay up balance!&quot;;
           } else if ($now &lt;= $Infor[2]['PaymentPlan']['submission_date'] &amp;&amp; $currentBalance &gt; 0){
              // Do something 
              echo &quot; Tell student to pay up balance!&quot;;
    }
  </code></pre>
  <p>How can I achieve this using <code>foreach()</code>? I am using CakePHP-2 and PHP5.6. I am not sure how best I can implement this.</p>