0

I have two arrays, there is one element which is 'name' common in first and second array. Now, I want to retrieved values from second array if first array value match to second one.

code for first array:

    $rs = array();
    foreach ( $ex_array as $data ) {

                $rs[] = array( 'name' => $data['name'] );

            }

Second Array:

$entries_data = array();
foreach ( $array as $entry ) {

            $name = $entry['name']['value'];
            $email = $entry['email']['value'];

            $entries_data[] = array(
                'name' => $name,
                'email' => $email
            );
        }

Problem is, there is only multiple names in first array, and then i have to compare first array names with the second one array, if there is match then whole data is retrieved from second array for specific name. I am trying to do this by using in_array function for search names in second array but can't fetch whole values. Any suggestions or help would be grateful for me.

1
  • Hay, can you post an example of those 2 arrays? Commented Nov 11, 2012 at 20:03

1 Answer 1

1

is_array() is used for 1d arrays which isnt ur case use this function taken from the php documentation comments and edited by me to work for ur example

function in_multiarray($elem, $array)
    {
        $top = sizeof($array) - 1;
        $bottom = 0;
        while($bottom <= $top)
        {
            if($array[$bottom]['name'] == $elem)
                return true;
            else 
                if(is_array($array[$bottom]['name']))
                    if(in_multiarray($elem, ($array[$bottom]['name'])))
                        return true;

            $bottom++;
        }        
        return false;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.