0

I have one associative array as follows:

{
  "organizations":[
    {
      "name":"10sheet",
      "owner_name":"Me"
    },
    {
      "name":"12Gigs",
      "owner_name":"Me"
    },
      "name":"24\/7 Card",
      "owner_name":"Me as well"
    },
}

I want to search using the name field in this first array against the name field in the following associative array:

[{"name": "Wetpaint",
  "permalink": "wetpaint",
  "category_code": "web"},
 {"name": "AdventNet",
  "permalink": "adventnet",
  "category_code": "enterprise"},
 {"name": "Zoho",
  "permalink": "zoho",
  "category_code": "software"},
 {"name": "Digg",
  "permalink": "digg",
  "category_code": "web"},
 {"name": "24/7 Card",
  "permalink": "247-card",
  "category_code": "other"}]

If there is a match take the value in the permalink field and put it into a new array. Also, in the first array there are escaping issues such as the 24/7 instead of 24/7 and the search should not be case sensitive. I'm trying to write this in PHP and working with these two APIs is killing me.

Thanks for your help!

-Greg

Greg
  • 89
  • 1
  • 9

1 Answers1

0

Untested, but should work:

<?php
$result = array();
foreach($obj["organizations"] as $o) {
    foreach($obj2 as $o2) {
        if(stristr($o["name"], $o2["name"])) {
            $result[] = $o2["permalink"];
        }
    }
}
?>

$obj is your first array, $obj2 the second .. $result contains the matches.

Daniel
  • 601
  • 1
  • 4
  • 13
  • Thanks for your response. I have it almost working but I want to do an array_search so if I have 'Reddit' in one array name and 'reddit' it another it finds the match. However, if I have for example 'redditmania' it would not return a match. – Greg Jul 05 '12 at 18:56
  • preg_match instead of stristr. Pass a regex with wildcards. Do it once again reverse to make it work both ways. http://php.net/manual/en/function.preg-match.php – Daniel Jul 07 '12 at 15:56