Jump to content

in_array search problem


NaGGi

Recommended Posts

Looked all search results but didnt quite found what I was looking for and my noob php brain can't figure the php manual out so I'll just ask.

 

I have an array which have another array inside and Id like to searh a value from that array

 

My array:

print_r($product_rows);

gives:

Array ( [0] => Array ( [row_color] => sectiontableentry1 [product_name] => Lattaaa pew
[product_attributes] => [product_sku] => xxxx [product_price] => 45.00 € )

 

Now I have modifer:

$db_sku = xxxx

 

Now I'd like to search if that xxxx value is in that array

 

How that if sentence should be written?

 

Atm my code looks like this but its not working

if (in_array(array($product_sku, $db_sku ),$product_rows) ) { echo found; } else { echo not_found; }

 

Any hints?

Link to comment
Share on other sites

You need a recursive loop/function.

 

<?php

function recur_in_array($array,$string){
   for($i=0;$i<count($array);$i++){
      if(is_array($array[$i])){
         $found = recur_in_array($array[$i],$string);
         if($found === true){
            return $found;
         }
      }else{
         if (in_array($string, $product_rows[0])) {
           return true;
         }
      }
   }
}

if(recur_in_array($array_var) === true){
   echo("xxx found");
}

?>

 

-CB-

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.