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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:24:58+00:00 2026-05-31T11:24:58+00:00

Refer to 2 array below: $bar_arr = Array ( Array ( [bar] => bar01.jpg

  • 0

Refer to 2 array below:

$bar_arr = 

Array
(
    Array
    (
        [bar] => bar01.jpg
        [position] => 1
    )
    Array
    (
        [bar] => bar02.jpg
        [position] => 2
    )
    Array
    (
        [bar] => bar03.jpg
        [position] => 3
    )
)

$banner_arr = 

Array
(
    Array
    (
        [banner] => 
        [position] => 1
    )
    Array
    (
        [banner] => banner02.jpg
        [position] => 2
    )
    Array
    (
        [banner] => banner03.jpg
        [position] => 3
    )
)

$banner_arr[0][banner] don’t have value, so I would like to remove this index. In the meantime$bar_arr[0][bar] would also be removed, I want to end up like this:

$bar_arr = 

Array
(
    Array
    (
        [bar] => bar02.jpg
        [position] => 2
    )
    Array
    (
        [bar] => bar03.jpg
        [position] => 3
    )
)

$banner_arr = 

Array
(
    Array
    (
        [banner] => banner02.jpg
        [position] => 2
    )
    Array
    (
        [banner] => banner03.jpg
        [position] => 3
    )
)

My question is how to compare this two array and remove both item in a specific index if either of the array have empty value.

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-05-31T11:24:59+00:00Added an answer on May 31, 2026 at 11:24 am

    If you’re just checking the value of banner and you assume that the two arrays are ordered identically, this is fairly simple (You might need to make a copy of banner_arr first … not sure):

    foreach ($banner_arr as $key => $banner) {
        if (empty($banner['banner'])) {
            unset($banner_arr[$key]);
            unset($bar_arr[$key]);
        }
    }
    

    More likely though, the order of the arrays can’t be relied upon. In this case, just use an additional array of positions and track all the positions that need to be removed, and unset those:

    $positions = array();
    foreach ($banner_arr as $key => $banner) {
        if (empty($banner['banner'])) {
            $positions[] = $banner['position'];
            unset($banner_arr[$key]);
        }
    }
    

    then search through $bar_arr for corresponding positions:

    foreach ($bar_arr as $key => $bar) {
        if (in_array($bar['position'], $positions)) {
            unset($bar_arr[$key]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C# language when you refer to an array element you can write: myclass.my_array['element_name']
I refer to this page: Post array of multiple checkbox values <input type=checkbox class=box
See http://jsfiddle.net/tAfkU/ When I'm looping through an array, how can I refer to the
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
Suppose I have a float[] where each position in the array has unique meaning.
For eg. I have an array of structs 'a' as below: struct mystruct{ int
In some contexts, we can use an array($this, 'variable') syntax, to refer to object
I want to be able to have a large master array and refer to
I try to refer to an array in the Game1 class by creating an
I've created a variable length array in one function, however I need to refer

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.