Jump to content

find match in the array


Jayram121

Recommended Posts

$phoneDevices = array(
			'iPhone'        => '\biPhone.*Mobile|\biPod', // |\biTunes
			'BlackBerry'    => 'BlackBerry|\bBB10\b|rim[0-9]+',
			'HTC'           => 'HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6400L|ADR6425|001HT|Inspire 4G|Android.*\bEVO\b',
			'Nexus'         => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile',
			// @todo: Is 'Dell Streak' a tablet or a phone? 
			'Dell'          => 'Dell.*Streak|Dell.*Aero|Dell.*Venue|DELL.*Venue Pro|Dell Flash|Dell Smoke|Dell Mini 3iX|XCD28|XCD35|\b001DL\b|\b101DL\b|\bGS01\b',
			'Samsung'       => 'Samsung|SGH-I337|BGT-S5230|GT-B2100|GT-B2700|GT-B2710|GT-B3210|GT-B3310|GT-B3410|GT-B3730|GT-B3740|GT-B5510|GT-B5512|GT-B5722|GT-B6520|GT-B7300|GT-B7320|GT-B7330|GT-B7350|GT-B7510|GT-S5350|GT-S5360|GT-S5369|GT-S5380|GT-S5380D|GT-S5560|GT-S5570|GT-S5600|GT-S5603|GT-S5610|GT-S5620|GT-S5660|GT-S5670|GT-S5690|GT-S5750|GT-S5780|GT-S5830|GT-S5839|GT-S6102|GT-S6500|GT-S7070|GT-S7200|GT-S7220|GT-S7230|GT-S7233|GT-S7250|GT-S7500|GT-S7530|GT-S7550|GT-S7562|GT-S7710|SPH-M920|SPH-M930|SPH-N100|SPH-N200|SPH-N240|SPH-N300|SPH-N400|SPH-Z400|SWC-E100|SCH-i909|GT-N7100|GT-N7105|SCH-I535',
			'Sony'          => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|SonyEricssonMT27i',
			'Asus'          => 'Asus.*Galaxy|PadFone.*Mobile',
		);

$searchValue ="GT-5830i";

 

In the array I am looking for the word, ‘GT-5530i’but in the array only GT-5530 word is there, without the last letter ‘i’.

How can I match this word?

 

 

Link to comment
https://forums.phpfreaks.com/topic/283118-find-match-in-the-array/
Share on other sites

$phoneDevices is an associative array which contains phone manufactures as the array index (key) and corresponding models as regex patterns (value).

 

Your current code most probably detects the manufacturer. Uses it as the key and performs a regex match on the phone models listed.

 

For your code to match other models, you just need to add it to the list, separate each model with a pipe character |.

 

If there two models named similarly, like GT-5830 and GT-5830then add i? after the model name in the list.

Either you have a typo or your description is inacurate, you havent got GT-5830 in your list but you have GT-S5830

You could hack all this around, but most probably it wont fit all your requirements.

But as an example on this exact question:

$searchValue ="GT-S5830i";

foreach($phoneDevices as $key => $devices){
  $device = explode('|',$devices);
  while(list($sub_key, $val) = each($device)) {
    if(stripos($searchValue,$val) !== false){
      echo 'Found '.$searchValue.' in '.$key.' list as '.$val; // Found GT-S5830i in Samsung list as GT-S5830
    }
  }
}

Result: Found GT-S5830i in Samsung list as GT-S5830

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.