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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:21:01+00:00 2026-05-25T15:21:01+00:00

How can I make two arrays correspond with each other? For instance, this the

  • 0

How can I make two arrays correspond with each other?

For instance, this the 1st-months array I generated,

Array
(
    [0] => Sep
    [1] => Oct
    [2] => Nov
    [3] => Dec
    [4] => Jan
    [5] => Feb
    [6] => Mar
    [7] => Apr
    [8] => May
    [9] => Jun
    [10] => Jul
    [11] => Aug
)

And this is the 2nd-months array,

Array
(
    [0] => Sep
    [1] => May
    [2] => Apr
)

But I want the 2nd-months array to follow the same order as the 1st-months array, to return this as the result,

Array
(
    [0] => Sep
    [1] => Apr
    [2] => May
)

Is it possible?

EDIT:

The code that I use to generate the month arrays above,

# Set month array for the calendar and for the items.
$months_calender = array();
$months_items = array();

# Set variable for requested month/year.
$requested_year = set_variable($_REQUEST,'year');
$requested_month = set_variable($_REQUEST,'month');

# Set current month and curren year.
$current_month = (int)date('m');
$current_year = (int)date('Y');

# Loop the 12 month and starts from the current month.
for($x = $current_month; $x < $current_month+12; $x++) $months_calender[] = date('M', mktime(0, 0, 0, $x, 1));
print_r($months_calender); 
//echo $current_year;

# Check if the requested by $_REQUEST does not exit then use the current month/year as the requested month/year.
$requested_year = $requested_year? $requested_year : $current_year;
$requested_month = $requested_month? $requested_month : date('m', mktime(0, 0, 0, $current_month, 1));
//var_dump($requested_year);
//echo $requested_month;

# Use the stored connection object from the class_page_controller.php, to process the query
$items_monthly = $connection->fetch_all($sql_items_monthly,array($requested_year));
$total_items_monthly = $connection->num_rows($sql_items_monthly,array($requested_year));
//print_r($items_monthly);

# Check if the total items is more than 0, then loop the result to make an 1-d array.
if($total_items_monthly > 0) foreach($items_monthly as $item_monthly) $months_items[] = $item_monthly['archiveMonth'];
print_r($months_items);

the sql,

$sql_items_monthly = "
    SELECT 
    DATE_FORMAT(p.pg_backdate, '%b') AS archiveMonth,
    COUNT(p.pg_backdate)

    FROM root_pages AS p
    WHERE DATE_FORMAT(p.pg_backdate, '%Y') = ?
    AND p.cat_id = '2'
    AND p.parent_id = '6'
    AND p.pg_hide != '1'

    GROUP BY archiveMonth
    ORDER BY p.pg_backdate DESC
";

EDIT:

It seems I can get the result by this,

$result = array_intersect($months_calender, $months_items);
print_r($result);

returns,

Array
(
    [0] => Sep
    [7] => Apr
    [8] => May
)

Even though the keys are not started from 0 to 2 but it does not matter. Unless you have a better solution.

  • 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-25T15:21:02+00:00Added an answer on May 25, 2026 at 3:21 pm

    A simple combination of array_intersect and ksort will do the trick:

    $array2 = array_intersect($array1, $array2);
    ksort($array2);
    

    See it in action.

    If for some reason you want to have consecutive integer keys after this, it’s also easy to reindex the resulting array:

    $array2 = array_values($array2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions: 1) How can I make an array which points to
I have two arrays in php and I need to make a new array
Suppose two lines of text correspond to each other word by word except for
I'm trying to make a function that compares two different length arrays to each
How can I make this two queries in one ? $query = SELECT *
How can I make two numeric arrays (one for keys one for values -
In PHP, you can make two variables point to the same data. $a =
If I make two iPhone applications, how can/should I share custom data (not contacts
I'm trying to make two XML attributes to be mutually exclusive. How can one
I need to have two UITableViews on one UIView. I can make it work

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.