Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Multidimensional Array Sum/Erase Problem
    primarykey
    data
    text
    <p>I have an array that looks like the following:</p> <p>The format:</p> <pre><code>[Person#] =&gt; Array ( [Bank#] =&gt; Balance . . [Bank#] =&gt; Balance ) </code></pre> <p>The Array:</p> <pre><code>[1] =&gt; Array ( [0] =&gt; 707 //Person #1 has 707 balance in Bank #0 [1] =&gt; 472 //Person #1 has 472 balance in Bank #1 ) [2] =&gt; Array ( [0] =&gt; 2614 [3] =&gt; 140 [1] =&gt; 2802 [4] =&gt; 245 [2] =&gt; 0 //Person #2 has 0 balance in Bank #2 ) [3] =&gt; Array ( [2] =&gt; 0 [3] =&gt; 0 [0] =&gt; 1710 [4] =&gt; 0 [1] =&gt; 575 ) [4] =&gt; Array ( [1] =&gt; 1105 [0] =&gt; 1010 [4] =&gt; 0 [3] =&gt; 120 [2] =&gt; 0 ) [5] =&gt; Array ( [1] =&gt; 238 [4] =&gt; 0 [0] =&gt; 0 ) [6] =&gt; Array ( [0] =&gt; 850 [1] =&gt; 0 ) [7] =&gt; Array ( [4] =&gt; 500 [0] =&gt; 3397 [1] =&gt; 2837 ) </code></pre> <p>The number to the left of the word "Array" represents a person. The first single digit number represents a bank. The second number represents a balance in the bank.</p> <p>I'm printing these numbers out in a table and, as you'll see in this example, Bank #2 has a zero balance for all people who have an account with Bank #2. I need a way to remove Bank #2 from the array -- and/or recreate the array without Bank #2. Of course, it won't always be Bank #2 that needs to be removed so it has to be a solution that finds any Banks with a total balance of zero (across all people) and removes it.</p> <p>Alternatively, I am fine with removing all zero balances from the array before going to print out the table.</p> <p>I'm not sure which is easier as I haven't been able to find a simple way to do either one.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload