How i get the specified array values
You can match against the patterns based on starting keys.
$array = [ ['BACK', 'PACK', 'BBP160800103', '', 'G086-1', '8#.JPG'], ['BACKPACK', 'BBP160500010', 'G114-3#1.JPG'], ['WSL160800024-WSL160800025', 'L83-5.JPG'], ['IA041017', 'L83-5.JPG']];$patterns = ['(BBP\w+)', '(WSL\w+)', '(IA\w+)'];$codes = [];$matcher = '/' . implode($patterns, '|') . '/';foreach ($array as $arr) { array_map(function ($value) use ($matcher, &$codes) { preg_match_all($matcher, $value, $matches); foreach($matches as $match) { $codes = array_merge(array_filter($match), $codes); } }, $arr);}print_r(array_unique($codes));// outputArray( [0] => IA041017 [2] => WSL160800024 [3] => WSL160800025 [6] => BBP160500010 [8] => BBP160800103)
Pass your final array to this function to achieve your result.
arraymakking($file);//your arrayfunction arraymakking($arr){ foreach($arr as $key=>$val){ if(strpos($val,'-') !== false){ $res=explode('-',$val); unset($arr[$key]); } } $result=array_merge($arr,$res); return $result;}
Try this:
echo $array[0][3]; //BBP160800103echo $array[2][1]; //BBP160500010
Etc. Refer to the indexing by number. You'd be better off creating your array with named indexes. Like this:
$array = array("Array1"=>array("key1"=>"val1","key2"=>"val2"),"Array2"=>(array("2ndKey1"=>"val1", "2ndKey2"=>"val2));