Take a value of multiple arrays within an array

Asked

Viewed 791 times

1

I have a question regarding an array, I have an array that stores several arrays inside, this is the result:

Array (
   [0] => Array ( 
       [membro_id] => 1465 
       [membro_nome] => Gustavo Silva de Oliveira 
       [membro_estado] => 4 
       [membro_cidade] => Humaití 
       [membro_status] => 1 
       [membro_validade] => 31/07/2018 
       [estado_id] => 4 
       [estado_codigouf] => 13 
       [estado_nome] => Amazonas
       [estado_uf] => AM
       [estado_regiao] => 1 
       [status_id] => 1
       [status_nome] => Ativo
   )
   [1] => Array (
       [membro_id] => 1581 
       [membro_nome] => Ânio Neves de Souza
       [membro_estado] => 4 
       [membro_cidade] => Manaus
       [membro_status] => 1
       [membro_validade] => 31/07/2019
       [estado_id] => 4
       [estado_codigouf] => 13
       [estado_nome] => Amazonas
       [estado_uf] => AM
       [estado_regiao] => 1
       [status_id] => 1
       [status_nome] => Ativo
   )
)

I want to take the field [membro_status] => 1 of each result, I did the following $membros[0]['membro_status'], but only the first returns array, someone could help out?

3 answers

2


  • If you have difficulty making the code just ask.

  • On the fly man, thank you!

  • 1

    Please inform us that your question has been answered.

  • @Victorhugo put the answer as right. It is below the place of the score. Only you have this power.

1

Use the foreach

foreach($arrays as $array) {
  $status = $array["membro_status"];
}

0

Simple.

$novoArray = array_column($seuArray,'membro_id');
print_r($novoArray);

It can be interesting using the third parameter where the array is returned with the key=>value. Example:

$novoArray = array_column($seuArray,'membro_status', 'membro_nome');
print_r($novoArray);

Where key is the column reported as third parameter and value the second parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.