0

I have this array:

0: {nome: "ELIANA CRISTINA GUILHERMITTI RODRIGUES - 49-Sócio-Administrador", eMail: null,…}
1: {nome: "SUZANA MARQUES LOBANCO - 49-Sócio-Administrador", fiador: "1",…}
2: {nome: "AMARILDO APARECIDO RODRIGUES - 49-Sócio-Administrador", eMail: null, cpf: "132.555.555-57",…}
3: {nome: "VALDEMIR FRANCISCO DA COSTA - 22-Sócio", eMail: null, cpf: "132.555.555-58",…}
4: {nome: "ANDRE LUIS LOBANCO - 49-Sócio-Administrador", eMail: null, cpf: "132.555.555-59",…}

The item number 1 has a specific word: fiador: "1". This means that only this user has an email. How can I get only this item->eMail? Only the item that has the word "fiador" has a valid email.

But, it is dynamic, so I´ll never know which one will have the word "fiador".

2
  • 1
    Could you please accept my answer if it helped you solve your issue. If it didn't I'm happy to try and assist you further Commented Oct 29, 2019 at 17:16
  • Thanks, dude! I forgot to reply! Commented Oct 30, 2019 at 18:07

1 Answer 1

2

Iterate through the array (unless we're talking about thousands of records) and check which has the fiador property set:

foreach($arr as $record) {
    if(isset($record['fiador'])) ...
}

The point is is that you can use isset() to check if the array has a specific index.

Alternatively you could filter the array so that only the records with fiador property set remain in the array:

function hasProperty($item) {
    return isset($item['fiador']);
}
array_filter($arr, "hasProperty");
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.