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 7646929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:20:09+00:00 2026-05-31T10:20:09+00:00

I have 2 arrays. 1 with items that should always be used and 1

  • 0

I have 2 arrays. 1 with items that should always be used and 1 with optional items.
What I want is a list of all possible combinations with these items.
The items in the array have to become attributes with a true or false value.

For example, the arrays

$requiredAttr = array('header', 'footer');
$optAttr = array('image');

Should give the following result:

header="false" footer="false"
header="false" footer="false" image="false"
header="false" footer="false" image="true"
header="true" footer="false"
header="true" footer="false" image="false"
header="true" footer="false" image="true"
header="false" footer="true"
header="false" footer="true" image="false"
header="false" footer="true" image="true"
header="true" footer="true"
header="true" footer="true" image="false"
header="true" footer="true" image="true"

Ofcourse this has the work with any number of items in both arrays.

  • 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-05-31T10:20:11+00:00Added an answer on May 31, 2026 at 10:20 am

    check this..
    change variable name according to your standard..
    i print all array for debuging.

    http://codepad.org/HK1plx9n

    more optimised code

    http://codepad.org/pwVOWeRJ

    <?php
    
    $requiredAttr = array('header', 'footer');
    $boolarr = array('true', 'false');
    $optAttr = array('image' );
    
    $larr  = combine_array($requiredAttr , $boolarr , '=');
    
    $a_arr = array_slice($larr , 0 , count($larr)/2);
    $b_arr = array_slice($larr , count($larr)/2 , count($larr)/2);
    
    
    $larr_1    = combine_array($a_arr , $b_arr , ' ');
    $larr     = combine_array($optAttr , $boolarr , '=');
    array_push($larr , ''); // for optional
    
    $larr_3  = combine_array($larr_1 , $larr , ' ');
    
    function combine_array($first_arr , $second_arr , $separator)
    {
        $combine_arr  = array();
        for($i=0;$i<count($first_arr) ; $i++)
        {
        for($j=0;$j<count($second_arr) ; $j++)
        {
            array_push($combine_arr , $first_arr[$i].$separator.$second_arr[$j]);
        } 
        }
        return $combine_arr;
    }
    
    
    
    print_r($larr_3);
    
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of items that should be selected in my tree control.
I have an array that has 22 items in it (it may also have
I am trying to compare two arrays that always have different dimensions. eg. arr1
I have an array of arrays and I would like to remove all the
I have an array ( C language) that should be initialized at compile time.
I have an accordion that binds data for each item from an array. I
I have an array (items) of custom class objects (catalogItem) each catalogItem has various
I have an array Items which has 10 elements. I need to remove the
So I have an array of items, which I am iterating through and grabbing
I have an array of 50 items and I would like to choose 5

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.