PHP foreach loop inside foreach loop? -


i have 2 foreach loop. in first foreach loop menu list , second foreach loop database fetch loop. want compare first foreach key second foreach value first foreach array result shown

   array (     [master/city] => city     [master/national_holiday] => national holiday     [master/operator_comments] => operator comments     [master/sensors] => sensors ) 

and second foreach array result

   array         (             [0] => array                 (                     [menu_url] => monitoring/tickets                     [menu_category] => monitoring                     [read] => 1                     [write] => 1                 )              [1] => array                 (                     [menu_url] => monitoring/serach_tickets                     [menu_category] => monitoring                     [read] => 1                     [write] => 1                 )              [2] => array                 (                     [menu_url] => master/national_holiday                     [menu_category] => monitoring                     [read] => 1                     [write] => 0                 ) ) 

i try use code not working fine

   foreach( $first_array $key => $value) {    foreach( $second_array $second ) {     if ($second['value'] == $key) {        echo "hi";     }    } } 

can suggest mistake.

my real code using in view

<?php                     $i = 1;                      foreach($first_array $k => $val) {                     ?>                     <tr>                       <td>{{ $i }}</td>                       <td class="mailbox-name">{{ $val }}</td>                     <?php                         foreach ($edit_rights['role_rights'] $rights) {                     ?>                                                                  <td><input type="checkbox" class="master_read" name="menu_master_read[]" <?php if ($rights['menu_url'] == $k) { echo 'checked'; } else {echo ''; }?> value="{{ $k }}"></td>                       <td><input type="checkbox" class="master_write" name="menu_master_write[]" value="{{ $k }}"></td>                     </tr>                      <?php } $i++;  } ?>                     </tr> 

as don't see relation between arrays, can guess looking for.

you may looking ralation of second array's menu_url , first array's key.

for need use $second['menu_url'] in second array.

foreach( $first_array $key => $value) {   foreach( $second_array $second ){     if ($second['menu_url'] == $key) {        echo "hi";     }    } } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -