如何在php中搜索数组中的特定字符串[关闭]

How to get particular string from array, I given example of array as below

Array
(
    [0] => Paper:300gsm Silk
    [1] =>  Lamination:Gloss
    [2] =>  Despatch:Standard 5 day
) 

I need to search if Despatch is available in array and if available then get value of it that's after given : and its Standard 5 day

there is not fix sequence in array and also there is not fix string like Despatch:Standard 5 day it may be change like Despatch:Standard 2 day,Despatch:Standard 5 day or may be Despatch:24 hours

Use array_walk() function with callback. Do substring search inside callback

You can use foreach and explode

foreach ($array as $value) {
   $exp = explode(':', $value);
   if ($exp[0] == 'Despatch') return $exp[1];
}

First of all, take a look at associative arrays. Then your array looks like this:

$myArray
(
    ['Paper'] => 300gsm Silk
    ['Lamination'] =>  Gloss
    ['Despatch'] =>  Standard 5 day
) 

And you can call it like this then:

$value = $myArray['Despatch']

Is this the result you want?

$arr = array("Paper:300gsm Silk",
            "Lamination:Gloss",
            "Despatch:Standard 5 day"
            );

$searchword = "Despatch";
$matches = array_filter($arr, function($var) use ($searchword) { return preg_match("/\b$searchword\b/i", $var); });


$res=substr($matches[2],9);
echo $res;