K
K
Kar922017-08-03 01:27:49
PHP
Kar92, 2017-08-03 01:27:49

How to get that id where "email": "[email protected]"?

how to get that id where "email" : "[email protected]"?

<?php
echo "<hr>";
echo "<br>";
$json = '{
        "Id" : {
               "Name" : "Karen",
                "email" : "[email protected]",
                "password" : "123456"
    },

        "ID2" : {
               "Name" : "Anush",
                               "email" : "[email protected]",
                               "password" : "1992120"
    }
}';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlxMrz, 2017-08-20
@AlxMrz

In general, like this:

<?php
echo "<hr>";
echo "<br>";
$json = '{
        "Id" : {
               "Name" : "Karen",
                "email" : "[email protected]",
                "password" : "123456"
    },

        "ID2" : {
               "Name" : "Anush",
                               "email" : "[email protected]",
                               "password" : "1992120"
    }
}';
$decoded = json_decode($json);

$expectedValue;
foreach($decoded as $key=>$value) {
  if($value->email=='[email protected]') {
    $expectedValue = $key;
  }
}
var_dump($expectedValue);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question