Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following php arrays

First array (

[0] => Array (

[0] => "you're so beautiful"

[1] => "you could be a part time model" )

[1] => Array (

[0] => "you're so beautiful"

[1] => "you could be an air hostess in the 60's" )

)

Second array (

[0] => Array (

[0] => "you're so beautiful"

[1] => "you could be a waitress" )

[1] => Array (

[0] => "you're so beautiful"

[1] => "you could be an air hostess in the 60's" )

)

What I want to do is search through the first array (and inside each one of the arrays) and check if the second field [1] is equal to another sentence inside another array. So basically:

foreach($first_array as $value){
    array_filter($second_array,function($second_array){
         return $second_array[1] = $value[1];
}

What I want is:

Desired array (

[0] => Array (

[0] => "you're so beautiful"

[1] => "you could be an air hostess in the 60's" )

)

because it's the only array where [1] is the common member, and so all of the array is filtered. The problem is return $second_array[1] = $value[1];. $value is not in the scope of the function, and $value depends of the out-of-scope foreach. Also, I'd like to know how I could filter all of the array as described. Thank you very much!

share|improve this question
1  
you can try use keyword –  mamdouh alramadan Apr 18 '14 at 14:52
    
@mamdouhalramadan so, this is how it feels to be in love... <3 –  0LLiena Apr 18 '14 at 14:57
1  
yep, that's what the php documentation all about, loving and sharing :D –  mamdouh alramadan Apr 18 '14 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.