title: Triple for loop with arrays
body: <p>I'm trying to get string with specific value. The issue is with FIND_IN_SET, because <code>$find_demographics</code> doesn't work propely if is outside for loop with <code>$j</code>. Also If I try to move <code>$$demographics_values</code> to the <code>$j</code> for loop, then names for values doesn't work.</p>
  
  <p>It's not important what is inside <code>user_about</code> or <code>m_z_analytics</code>, because I only want to insert right value inside FIND_IN_SET in <code>$$demographics_values</code> string.</p>
  
  <p>PS. How I could change the code to get the fastest response for 5.6 version?</p>
  
  <p><strong>Sample expectations for <code>$$demographics_values</code> string:</strong></p>
  
  <pre><code>$g_demographics_value_1 = $db-&gt;Query("$shortcode FIND_IN_SET('a01', b.about_education)");
  ...
  $g_demographics_value_18 = $db-&gt;Query("$shortcode FIND_IN_SET('b01', b.about_personal)");
  $g_demographics_value_19 = $db-&gt;Query("$shortcode FIND_IN_SET('b02', b.about_personal)");
  $g_demographics_value_20 = $db-&gt;Query("$shortcode FIND_IN_SET('c01', b.about_personal)");
  $g_demographics_value_21 = $db-&gt;Query("$shortcode FIND_IN_SET('c02', b.about_personal)");
  $g_demographics_value_22 = $db-&gt;Query("$shortcode FIND_IN_SET('c03', b.about_personal)");
  ...
  // the last string
  $g_demographics_value_73 = $db-&gt;Query("$shortcode FIND_IN_SET('g27', b.about_work)");
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>$shortcode = "SELECT COUNT(a.id) AS id FROM m_z_analytics a LEFT JOIN user_about b ON a.user_id=b.id WHERE";
  
  $a_l_demographics = [17,2,10,2,3,12,27];
  $a_p_demographics  = ['a','b','c','d','e','f','g'];
  $a_c_demographics = min(count($a_l_demographics), count($a_p_demographics));
  
  for ($i = 0, $k = 1; $i &lt; $a_c_demographics, $k &lt;= array_sum($a_l_demographics); $i++, $k++) {
  
    $demographics_values = 'g_demographics_value_'.$k;
  
    for ($j = 1; $j &lt;= $a_l_demographics[$i]; $j++) {
  
      // $i here shows 00000000000000000112222222222334445555...
  
      $find_demographics = $a_p_demographics[$i] . str_pad($j, 2, 0, STR_PAD_LEFT);
  
    }
  
    // $k is important for me to get value from the right rows in database. $k is based on array_sum($a_l_demographics)
  
    switch (true) {
      case $k &lt;= 1:
  
        // from $find_demographics I should get for example `a01`, to use it later in FIND_IN_SET('a01', b.about_education)
  
        $$demographics_values = $db-&gt;Query("$shortcode FIND_IN_SET('".$find_demographics."', b.about_education)");
  
        // I expect: $g_demographics_value_1['id'] have `a01` in FIND_IN_SET, $g_demographics_value_2['id'] `a02`...
  
        break;
      case $k &lt;= 17:
        $$demographics_values = $db-&gt;Query("$shortcode FIND_IN_SET('".$find_demographics."', b.about_personal)");
        break;
      case $k &lt;= 36:
        $$demographics_values = $db-&gt;Query("$shortcode FIND_IN_SET('".$find_demographics."', b.about_work)");
        break;
    }
  
  }
  </code></pre>