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

The Archive Base Latest Questions

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

I have an array that is filled with values dynamically and I have to

  • 0

I have an array that is filled with values dynamically and I have to check if a value exists.

I tried the follwing but it’s not working:

while (.....) {
    $fileData[] = array( "sku" => $sku, "qty" => $qty);
}

$product_sku = $product->getSku();

if (in_array(array("sku",$product_sku), $fileData)){
    echo "OK <BR/>";    
}
else{
    echo "NOT FOUND <BR/>"; 
}

The whole thing with keys confuses me. Should I change the table structure or just the in_array() statement? Can you help me find a 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:29:05+00:00Added an answer on May 25, 2026 at 3:29 pm

    You can see if a key exists in an array with:

    array_key_exists('sku', $fileData);
    

    also, you can just check it directly:

    if (isset($fileData['sku'])
    

    It looks like you might be trying to recursively check for a key though? I think we’d need to see what getSku() returns. $fileData[] appends a value to an existing array so if $fileData was an empty array you’d have

    fileData[0] = array("sku" => $sku, "qty" => $qty);
    

    not

    fileData = array("sku" => $sku, "qty" => $qty);
    

    Try this on for size (with some fake data for demo purposes):

    $fileData = array(
        array("sku" => "sku1", "qty" => 1),
        array("sku" => "sku2", "qty" => 2),
    );
    
    $sku = "sku2"; // here's the sku we want to find
    $skuExists = false;
    
    // loop through file datas
    foreach ($fileData as $data)
    {
        // data is set to each array in fileData
        // check if sku exists in that array
        if (in_array($sku, $data))
        {
            // if it does, exit the loop and flag
            $skuExists = true;
            break;
        }
    }
    
    if ($skuExists)
    {
        // do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array and filled its values like that: $('#list input:checked').each(function() { deleteRecordIdsStr.push($(this).attr('name'));
I have an array that has keys and values. For eg: Array ( [name]
I have an array that contains the RGB colour values for each pixel in
I have an array that I want to sort based on the value of
I have an assoc array filled with the values necessary for a PDOstatement. Should
I have a perl script that writes out an array filled with integers to
I have array with alphanumeric key values..While filling array on particular condition I have
I have an array filled with values (twitter ids) and I would like to
I have an array of values that I would like to run through htmlspecialchars
I have a numpy one dimensional array c that is supposed to be filled

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.