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

  • Home
  • SEARCH
  • 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 7524729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:08:35+00:00 2026-05-30T03:08:35+00:00

This could be solved with array_slice if the k/v pairs were in a predictable

  • 0

This could be solved with array_slice if the k/v pairs were in a predictable place,
unfortunately they’ve been scattered at random throughout the array and I have to
create my own silly little method to reassign things. Unfortunately my while loop here doesn’t unset squat…. Is there (of course there is) a better method, or a way to correct this behavior?

The loop for reassigning and blacklisting keys.

            $reports = array(
                  'inspection_number'   =>"{$array['report_key']}",
                  'customer_number'     =>"{$array['customer_number']}",
                  'customer_division'   =>"{$array['customer_division']}",
                  'report_date'         =>"{$array['report_date']}",
                  'customer'            =>"{$array['customer']}",
                  'location'            =>"{$array['location']}",
                  'region'              =>"{$array['region']}",
            );

            while (list($k, $v) = each($reports)) {
                if($array[$k]) { unset($array[$k], $array[$v]); }
            }

The arrays, you can see $array still has the $reports keys in it.

array (
  'shipper' => '',
  'status' => '',
  'po' => '',
  'location' => '',
  'inspector' => '',
  'commodity' => '',
  'count' => '',
  'size' => '',
  'label' => '',
  'variety' => '',
  'pack_date' => '',
  'comments' => '',
  'report_key' => '',
  'region' => '',
  'type' => 'melons',
  'report_date' => '1969-12-31',
  'customer_number' => '',
  'customer' => '',
  'customer_division' => '',
  'staged' => 'true',
)array (
  '`inspection_number`' => '\'\'',
  '`customer_number`' => '\'\'',
  '`customer_division`' => '\'\'',
  '`report_date`' => '\'1969-12-31\'',
  '`customer`' => '\'\'',
  '`location`' => '\'\'',
  '`region`' => '\'\'',
)

EDIT

So as you can see, the second array STILL contains keys that are in the first array,
these are not being unset. Even if I do a multiple recursion loop like this

foreach($reports as $reportsKey => $reportsValue) {
foreach($array as $arrayKey => &$arrayValue) {
    if($reportsKey == $arrayKey) { unset($arrayKey); }
} }

I am trying to assign the keys in $reports, the keys/values from $array,
then unset the copied keys from $array. This COULD be done with array_slice()
if the position of the keys in $array were predictable, but unfortunately they
aren’t.

Strangely even trying to assign the keys that DON’T exist in $reports doesn’t work

$tmp = array();
foreach($array as $ak => $av) {
    // if $reports['key_name'] does not exist, assign it to a new array.
    if(!$reports[$ak]) { $tmp[$ak] = $av; }
}
  • 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-30T03:08:36+00:00Added an answer on May 30, 2026 at 3:08 am

    array_diff_assoc gave me the results I needed

    $reports = array(
          'inspection_number'   =>"{$array['report_key']}",
          'customer_number'     =>"{$array['customer_number']}",
          'customer_division'   =>"{$array['customer_division']}",
          'report_date'         =>"{$array['report_date']}",
          'customer'            =>"{$array['customer']}",
          'location'            =>"{$array['location']}",
          'region'              =>"{$array['region']}",
    );
    
    $array = array_diff_assoc($array, $reports);
    echo '<pre>'; var_export($array); var_export($reports); echo '</pre>'; break;
    
    array (
      'shipper' => '',
      'status' => '',
      'po' => '',
      'inspector' => '',
      'commodity' => '',
      'count' => '',
      'size' => '',
      'label' => '',
      'variety' => '',
      'pack_date' => '',
      'comments' => '',
      'report_key' => '',
      'type' => 'melons',
      'staged' => 'true',
    )
    
    array (
      'inspection_number' => '',
      'customer_number' => '',
      'customer_division' => '',
      'report_date' => '1969-12-31',
      'customer' => '',
      'location' => '',
      'region' => '',
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem for a while, but couldn't with
This could be weird, Have you ever come across a blog which you wanted
This could be considered a duplicate question, as a similar one has already been
I could solve this using loops, but I am trying think in vectors so
Is there any good practice for this? I wish I could solve the problem
This could be a little off the ballpark, but a friend asked me about
This could quite possibly be the dumbest question ever asked. Our client wants us
This could save me so much time. Sometimes I find myself writing things like
I suppose this could apply to any dynamic language, but the one I'm using
Can anybody please explain how this could possibly happen? I am completely aware of

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.