Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:49:24+00:00 2026-06-14T16:49:24+00:00

Thanks in advance for looking. I am trying to build some HTML using a

  • 0

Thanks in advance for looking.

I am trying to build some HTML using a foreach loop with a few layers of arrays.

Groups of data and groups of titles for that data are stored in sets of arrays.
In turn, those arrays of data are stored in an array ($titlegroups and datagroups).

The aim being to set up a nested loop, where each group of data and titles populate the relevant fields in some html.

Here is a full set of code (structure) of my attempt.

$a=1;
$b=2;
$c=3;
$d=4;


$titlesA=array('string1','string2');
$titlesB=array('string3','string4');

$dataA=array($a,$b);
$dataB=array($c,$d);

$titlegroups=array($titlesA,$titlesB);
$datagroups=array($dataA,$dataB);
$groups=array(array_combine($titlegroups, $datagroups));

$j=0;   
foreach($groups as $titlesX => $dataX)
    {
        $j++;
        echo'<div class="something">';

        $i=0;
        foreach(array_combine($titlesX, $dataX) as $title => $var)
            {
            $i++;
            echo '
                    <li>'.$title.'</li><input name="'.$j.'x'.$i.'" value="'.$var.'" />
                ';
            }
        echo '</div>';
    }

Checking it in ideone I get the error:

Warning: array_combine() expects parameter 1 to be array, integer
given in /home/0zw0mb/prog.php on line 26

Line 26 is:

foreach(array_combine($titlesX, $dataX) as $title => $var)

but $titlesX and $dataX should both be arrays?

If anyone can set me straight I’d appreciate it. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:49:25+00:00Added an answer on June 14, 2026 at 4:49 pm

    You can’t have arrays as keys, they are converted to strings. You logic required some changes and an additional sentinel variable ($idx), to tell when the code crosses one group to another.

    array_merge was necessary due to the key requirements of arrays.

    Check the below code:

    $a=1;
    $b=2;
    $c=3;
    $d=4;
    
    
    $titlesA=array('string1','string2');
    $titlesB=array('string3','string4');
    
    $dataA=array($a,$b);
    $dataB=array($c,$d);
    
    $titlegroups=array_merge($titlesA,$titlesB);
    $datagroups=array_merge($dataA,$dataB);
    
    $items=array_combine($titlegroups, $datagroups);
    
    $indexes = array(count($dataA), count($dataB));
    
    $i = 0;
    $j = 0;
    $idx = $indexes[$j];
    
    echo '<div class="something">';
    
    foreach($items as $title => $var)
        {
                echo '
                        <li>'.$title.'</li><input name="'.$j.'x'.($i++).'" value="'.$var.'" />
                    ';
            $idx--;
    
            if ($idx == 0) {
                /* End of a group */
                echo '</div>';
                $idx = $indexes[++$j];
    
                /* If there is another group, create new container */
                if ($idx != null) {
                    echo '<div class="something">';
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks in advance for looking at this. Essentially, I'm calling didInsertElement() and binding an
Thanks in advance for taking the time to read my question. I'm using MySQL
thanks in advance for reviewing my post. I've only been using jquery for about
Looking for some help with arrays and pointers and explanation of what I am
I have an questions for you, thanks in advance for looking this question. I
Im looking for help with trying to vary a variable-name in a for loop:
This is a total newbie question, so thanks in advance. I'm trying to get
I am trying to create a report and am looking to pull out some
(Thanks in advance, SOers!) Problem I'm trying to solve Is there a way (e.g.,
Thanks in advance to anyone who can think of a more efficient or a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.