title: Foreach on Array taking too loong
body: <p>I am writing a script which should return me two values in an array from my database in combination with Wordpress and WooCommmerce. </p>
  
  <p>However the script is taking forever to load so I either get a 524 from cloudflare or it finishes and displays nothing. I already set Max execution time to 1 hour.</p>
  
  <p>Is there maybe anything that can be optimized with my code to achieve the same thing? </p>
  
  <pre><code>&lt;?php 
  ini_set('display_errors', 'On');
  include 'wp-load.php';
  
  function user_balance($user_id){
  
      $args = array(
      'customer' =&gt; $user_id,
      );
  
  $customer_orders = wc_get_orders( $args );
  $count           = 0;
   foreach ( $customer_orders as $customer_order ) :
      $order = wc_get_order( $customer_order );
      $invs  = $order-&gt;get_meta( 'type', true, 'view' );
      if ( $order-&gt;status == "completed" ):
          foreach ( $order-&gt;get_items() as $item_id =&gt; $item_data ) {
              $count += $item_data-&gt;get_quantity();
          }
      endif;
   endforeach;
  return $count;
  }
  
  if(current_user_can('administrator')){
  $args = array(
  'blog_id'      =&gt; $GLOBALS['blog_id'],
  'role'         =&gt; '',
  'role__in'     =&gt; array(),
  'role__not_in' =&gt; array(),
  'meta_key'     =&gt; '',
  'meta_value'   =&gt; '',
  'meta_compare' =&gt; '',
  'meta_query'   =&gt; array(),
  'date_query'   =&gt; array(),        
  'include'      =&gt; array(),
  'exclude'      =&gt; array(),
  'orderby'      =&gt; 'login',
  'order'        =&gt; 'ASC',
  'offset'       =&gt; '',
  'search'       =&gt; '',
  'number'       =&gt; '',
  'count_total'  =&gt; false,
  'fields'       =&gt; 'ID',
  'who'          =&gt; '',
  ); 
  
  $userIDs = get_users($args);
  
  
  
  foreach($userIDs as $key=&gt;$userID){
  
  $userID = array(
   'uid' =&gt; $userID,
   'balance' =&gt; user_balance($userID[$key])
  );
  
  }  
  
      echo '&lt;pre&gt;'; print_r($userIDs); echo '&lt;/pre&gt;';
  
  
   }
   ?&gt;
  </code></pre>