I have two foreach loop. In first foreach loop menu list and second foreach loop is database fetch loop. So i want compare first foreach key to second foreach value first foreach array result is 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 to use this code but not working fine
foreach( $first_array as $key => $value) {
foreach( $second_array as $second ) {
if ($second['value'] == $key) {
echo "Hi";
}
}
}
can you suggest what is my mistake.
My real code using in view
<?php
$i = 1;
foreach($first_array as $k => $val) {
?>
<tr>
<td>{{ $i }}</td>
<td class="mailbox-name">{{ $val }}</td>
<?php
foreach ($edit_rights['role_rights'] as $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>
$second['value']will be null or rather an error 'undefined index')