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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:18:40+00:00 2026-06-12T01:18:40+00:00

I am asking Similar question compare request values to array – it doesn’t work

  • 0

I am asking Similar question compare request values to array – it doesn’t work to me, my scenario is totally different

    $mkt =   array(
        array( 
            'title' => "Photos", 
            'iconlink' => "http://example.com/xyz.png",
            'pkg' => 'test' 
        ),
        array( 
            'title' => "code",
            'iconlink' => "http://example.com/xyz.png",
            'pkg' => 'main' 
        ),
        array( 
            'title' => "code",
            'iconlink' => "http://example.com/xyz.png",
            'pkg' => 'main' 
        ));

I am having logic issue in this problem, problem is i am getting value via $_REQUEST variable and then i compare this request value to array pkg element. If comparison is true then i want to get another elements except to matched one. In this as suggested, i am using unset to remove the key of element which is matched and all array point to new variable, it working but not for first element of array, it shows null when i compare request variable to first element of array:

 $mkt = array();
$newArray = $mkt;

foreach ($newArray as $key => $value ) {

    if (in_array($pn, $mkt, true)) {
        unset($newArray[$key]);
    }
}

$rand_ad = array_rand( $newArray, 1 );

echo json_encode( $newArray[$rand_ad] );

Please have a look on this issue very grateful to me.

  • 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-06-12T01:18:42+00:00Added an answer on June 12, 2026 at 1:18 am

    Loop in each value, if $pn is equal with that loop’s pkg then unset than unset that element:

    $pn = 'main';
    $newArray = $mkt;
    foreach ($newArray as $key => $val) {
        if ($pn == $val['pkg']) {
            unset($newArray[$key]);
        }
    }
    echo json_encode($newArray);
    // [{"title":"Photos","iconlink":"http:\/\/example.com\/xyz.png","pkg":"test"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was a similar question posted asking in general about alternatives to Qt. Well,
Notice that I am asking for little-o here (see similar question here ) -
Similar to this question asking about relatively light-weight data entry / editor application development,
A similar question has been asked, but since it always depends, I'm asking for
Sorry to be asking such similar question again, I am trying to read the
I've kind of asked this question earlier so sorry for asking a bit similar
I am asking this question on SO because a similar question was asked here
I'm asking a question very similar to this one —dare I say identical? An
I was asking the similar question last saturday, but seems like the smart folks
I apologize in advance about asking a so similar question, but i'm rather frustrated,

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.