K
K
Kar922017-08-14 19:14:24
PHP
Kar92, 2017-08-14 19:14:24

How to get that email where email is equal to [email protected]?

<?php
$json = 'id1 = {
    "name":"Karen",
    "email":[email protected],
    "password":123456
    "activation":0,
},
id2 = {
    "name":"Anush",
    "email":[email protected],
    "password":654321
    "activation":0,
},
id3 = {
    "name":"Vahe",
    "email":[email protected],
    "password":vahe1992
    "activation":0,
}
}';
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-08-14
@sergiks

$data = json_decode($json);
$found = false;
foreach($data as $person) {
  if( $person->email === '[email protected]') {
    $found = $person;
    break;
  }
}

if( $found) {
  // нашёлся! – он в переменной $found
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question