php - Change values on a multidimensional array key based with the value in the same key on another array -


i have 2 arrays:

 $s_array: array (     [0] => array         (             [field_1] => s. miguel             [field_2] => continente             [valor] => 0         ) [1] => array     (         [field_1] => s. miguel         [field_2] => guarita         [valor] => 0     )  [2] => array     (         [field_1] => s. miguel         [field_2] => manteiga         [valor] => 0     )  [3] => array     (         [field_1] => s. miguel         [field_2] => solmar         [valor] => 0     )  [4] => array     (         [field_1] => terceira         [field_2] => continente         [valor] => 0     )  [5] => array     (         [field_1] => terceira         [field_2] => guarita         [valor] => 0     )  [6] => array     (         [field_1] => terceira         [field_2] => manteiga         [valor] => 0     )  [7] => array     (         [field_1] => terceira         [field_2] => solmar         [valor] => 0     )  ) 

and:

 $r_array: array (     [0] => array         (             [field_1] => s. miguel             [field_2] => continente             [valor] => 185         )  [1] => array     (         [field_1] => s. miguel         [field_2] => manteiga         [valor] => 208     )  [2] => array     (         [field_1] => s. miguel         [field_2] => solmar         [valor] => 187     )  [3] => array     (         [field_1] => terceira         [field_2] => continente         [valor] => 192     )  [4] => array     (         [field_1] => terceira         [field_2] => guarita         [valor] => 199     ) 

)

what need change values of key [valor] on $s_array values key [valor] on $r_array in case other keys [field_1] , [field_2] have same values on both arrays.

thanks help.

try should fine consider both array must same size

<?php  for($i=0 ; $i<count($s_array) ; $i++){      $s_element = $s_array[$i];     $r_element = $r_array[$i];      if(($s_element["field_1"]==$r_element["field_1"]) && ($s_element["field_2"]==$r_element["field_2"]) ){         $s_array[$i]["valor"] = $r_array[$i]["valor"]     } }  ?> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -