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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:45:07+00:00 2026-05-25T19:45:07+00:00

In my application , I have few parameters (zone_id, startdate, enddate, brand, model) which

  • 0

In my application , I have few parameters (zone_id, startdate, enddate, brand, model) which I get from my UI form . Each of these parameters is an array containing 1 or more parameters .

My form parameters looks something like this :

Array
(
[sel_date_option] => today
[startdate] => 2011-09-19
[enddate] => 2011-09-19
[zone_id] => 1576,1562,1561
[model] => Array
    (
        [0] => A300
    )

[brand] => Array
    (
        [0] => ACTS
    )

)

Now , I want to generate keys which are combinations of these parameters . They would be something like :

[zone_id]_[model]_[brand]_[model]_[startdate]_[enddate]

This reflect all the possible arrangements of the above values .
For the above inputs, I should get the following keys :

1576_ACTS_A300_2011-09-19
1562_ACTS_A300_2011-09-19
1561_ACTS_A300_2011-09-19

Inside of giving the same startdate and enddate once can also enter a period like from 2011-09-19 to 2011-09-21.

What I am doing is I am using nested looping through all the parameter array and then creating a complex array of arrays something like the following :

Array
(
[0] => Array
    (
        [0] => 1576_DZ_A300
    )

[1] => Array
    (
        [0] => 1576_DZ_A300
        [1] => 1562_DZ_A300
    )

[2] => Array
    (
        [0] => 1576_DZ_A300
        [1] => 1562_DZ_A300
        [2] => 1561_DZ_A300
    )

[3] => Array
    (
        [0] => 1576_DZ_A300
        [1] => 1562_DZ_A300
        [2] => 1561_DZ_A300
        [3] => 1563_DZ_A300
    )
 )

What I am doing is first I creating an array of all zones as :

Array
(
[0] => 1576
[1] => 1562
[2] => 1561
[3] => 1563
)

Then I am looping it using a nested loop for all the possible models and brands array like this :

function getInventoryData($criteria)
{

    $index = "";

    if($criteria['zone_id']!='')
    {
        $zone = explode(',', $criteria['zone_id']);
        for($i=0;$i<count($zone);$i++)
        {
            $index[] .= $zone[$i];
        }

        echo '<pre>';print_r($index);exit;
    }

    if(!empty($criteria['model']))
    {
        foreach($index as $key=>$value)
        {
            foreach($criteria['model'] as $model)
            {
                $temparr[] = $index[$key].'_'.$model;
            }
            $index[$key] = $temparr;
        }

    }

Now , is there any other efficient method to achieve this ?

Moreover , there is another overhead associated with the above method :

While reading the generated keys , I have to loop through all the levels and in case of large sequence of data , the complexity can be really a matter of concern.

  • 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-25T19:45:08+00:00Added an answer on May 25, 2026 at 7:45 pm

    If I understand what you are trying to do correctly, this the most efficient method I can come up with for doing the above:

    function getInventoryData ($arr) {
      // Make sure all required keys are set
      if (!isset($arr['zone_id'],$arr['model'],$arr['brand'],$arr['startdate'],$arr['enddate'])) return FALSE;
      // Make a date string for the end of the keys
      $dateStr = $arr['startdate'].(($arr['startdate'] == $arr['enddate']) ? '' : '_'.$arr['enddate']);
      // Normalise the data
      if (!count($arr['zone_id'] = array_unique(explode(',',$arr['zone_id']))) || !count($arr['brand'] = array_unique($arr['brand'])) || !count($arr['model'] = array_unique($arr['model']))) return FALSE;
      // Get all possible permutations
      $result = array();
      foreach ($arr['zone_id'] as $zone) foreach ($arr['brand'] as $brand) foreach ($arr['model'] as $model) $result[] = "{$zone}_{$brand}_{$model}_{$dateStr}";
      // Return the result
      return $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python application which needs quite a few (~30) configuration parameters. Up
Have the following scenario. I have a few form, which essentially have a few
We have a few projects that involve building an application that is composed of
How do you unit test a large MFC UI application? We have a few
I have a pure Winapi application that needs a few new features. One of
I have few different applications among which I'd like to share a C# enum.
I have a few C# .dll projects which are common to many applications. Currently,
I have few global methods declared in public class in my ASP.NET web application.
Our application is interfacing with a lot of web services these days. We have
I have a few areas in my application that are relatively independent (all navigated

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.