Changing values of a two-dimensional array - PHP

Asked

Viewed 5,815 times

1

Hello.

I need to assemble a foreach to update the array values below:

Array
(
   [0] => Array
       (
        [id] => 1
        [profissao] => Ajudante de cozinha
        [interesse] => 
       )

   [1] => Array
       (
        [id] => 2
        [profissao] => Manobrista
        [interesse] => 
       )

   [2] => Array
       (
        [id] => 3
        [profissao] => Porteiro
        [interesse] => 
       )

   [3] => Array
       (
        [id] => 4
        [profissao] => Vigia
        [interesse] => 
       )

   [4] => Array
       (
        [id] => 5
        [profissao] => Zelador
        [interesse] => 
       )

   [5] => Array
       (
        [id] => 6
        [profissao] => Arrumadeira
        [interesse] => 
       )

   [6] => Array
       (
        [id] => 7
        [profissao] => Babá
        [interesse] => 
       )

   [7] => Array
       (
        [id] => 8
        [profissao] => Babá folgista
        [interesse] => 
       )

   [8] => Array
       (
        [id] => 9
        [profissao] => Caseiro
        [interesse] => 
       )

   [9] => Array
       (
        [id] => 10
        [profissao] => Copeira(o)
        [interesse] => 
       )
)
  • How you want the array to end?

  • I just need to update the values of interest, ([interest] => 1), go through the array and update the values @bfavaretto

1 answer

3


You can walk through it like this:

foreach($myArray as $key => $subarray) {
      $myArray[$key]['interesse'] = '1';
      // ...
}

DEMO

Browser other questions tagged

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