C
C
CrewCut2016-06-21 15:33:29
PHP
CrewCut, 2016-06-21 15:33:29

How to remove words contained in another array in an array from strings?

There is an array, for example:
array1 = ( 'красная шапочка', 'серый волк' )
and another one:
array2 = ( 'красная', 'серый' )
What is the best way to get an array res= ( 'шапочка', 'волк' )?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
Urvin, 2016-06-21
@CrewCut

Well, for example:

$array1 = ['красная шапочка', 'серый волк'];
$array2 = ['красная', 'серый'];

function rep($val)
{
  global $array2;
  return str_replace($array2, '', $val);
}

$array3 = array_map('rep', $array1);

print_r($array3);

Y
yuras666, 2016-06-21
@yuras666

array_map('trim', str_replace($array2, "", $array1));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question