0

I have multidimensional array like following,

 $_users = array(
            array(
                'uid' => '1', 
                'fname' => 'T1',
                'lname' => 'N1',
                'login' => 'Test',
                'email' => 't@test.com',
            ),
           array(
                'uid' => '2', 
                'fname' => 'T2',
                'lname' => 'N2',
                'login' => 'Test',
                'email' => 't@test.com',
            ),
          array(
                'uid' => '3', 
                'fname' => 'T3',
                'lname' => 'N3',
                'login' => 'John',
                'email' => 'john@test.com',
            )
        );

Now i am trying to check in this array if login and email same, then i am adding newemail address like following,

$_users = array(
                array(
                    'uid' => '1', 
                    'fname' => 'T1',
                    'lname' => 'N1',
                    'login' => 'Test',
                    'email' => 't@test.com',
                    'new_email' => 't@test.com',

                ),
               array(
                    'uid' => '2', 
                    'fname' => 'T2',
                    'lname' => 'N2',
                    'login' => 'Test',
                    'email' => 't@test.com',
                    'new_email' => '2_Test_t@test.com',
                ),
              array(
                    'uid' => '3', 
                    'fname' => 'T3',
                    'lname' => 'N3',
                    'login' => 'John',
                    'email' => 'john@test.com',
                    'new_email' => 'john@test.com',
                )
            );

I am stuck with this and now getting how to get this. can you please someone help me here. Thanks,

  • 1
    Possible duplicate of [PHP multidimensional array search by value](https://stackoverflow.com/questions/6661530/php-multidimensional-array-search-by-value) – SAMUEL Feb 21 '18 at 06:40
  • 1
    Thanks for you comment but there are 20,000 emails and login in my array. In sort my array count is 20,000. I am new to php and not getting how search it. – Richa Sharma Feb 21 '18 at 06:45
  • search email and login value are same? so in that case to check for both the code will update email for first match. – Noman Feb 21 '18 at 07:28

1 Answers1

0
$a = "Test";
$b = "t@test.com";

$i = 0;
foreach ($_users as $value){

    //echo $value['login'];
    if($value['login'] === $a && $value['email'] === $b){

        //ADd Data
        $_users[$i]['new_email'] = "2_Test_t@test.com";

    }

$i++;
}

echo "<pre>";
print_r($_users);

Live Demonstration

TarangP
  • 2,711
  • 5
  • 20
  • 41
  • It seems its changing the first match record. 2_Test_t@test.com. Here 2 is the uid. When first record should be changed. – Richa Sharma Feb 21 '18 at 07:00