How to read items from one array within another?

Asked

Viewed 60 times

-2

This is my multidimensional array:

<?php  
  $beneficiarios = array
        (


            array(

                "codigo_membro" =>$cod,
                "nome" => $_POST['nome1'],
                "n_identificacao" => $_POST['n_identificacao1'],
                "parentesco" => $_POST['parentesco1'],
                "telefone" => $_POST['telefone1'],
                "email" => $_POST['email1']
            ),
            array(
                "codigo_membro" => $cod,
                "nome" => $_POST['nome2'],
                "n_identificacao" => $_POST['n_identificacao2'],
                "telefone" => $_POST['telefone2'],
                "email" => $_POST['email2']
            )


        );

?>

I would like to read the elements within each array in the multidimensional array.

For example: I would like to be able to print what is written 'name' for each array.

I believe a loop of repetition might apply, but I’m out of ideas tried:

<?php echo $beneficiarios[0][1]?>

But you’re making a mistake.

  • And so: <?php echo $beneficiarios[0]['nome']?>?

  • https://ideone.com/LV5eu8

  • Thank you very much... So far it works (ideone.com/Lv5eu8 ), but I would like to be able to print all the information of each array through the positions of the same.. thank you in advance.

1 answer

0

I made some adjustments to this code and got the result. I would like to share. (example code)

    <?php

  $Array = array(
   array("Conta" => "FRANCIELE OLIVEIRA", "CPF" => "", "TelefoneRes"=> '(00) 0000-0000'),
   array("Conta" => "BEATRIX BEHN", "CPF" => "", "TelefoneRes"=> '(00) 0000-0')
                                                        );
$i = 0;
foreach ($Array as $result):
       $i++;
 extract($result);
 ?>
 <tr>
 <td class="text-left col-md-9 control-label"> <?php echo $Conta ?></td>
 <td class="text-left col-md-9 control-label"> <?php  echo $CPF ?></td>
 <td class="text-left col-md-9 control-label"> <?php echo $TelefoneRes ?></td>

</tr>
    <?php
endforeach;
               ?>
Thank you for your attention.

Browser other questions tagged

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