我有两组代表所有数据和选定数据的数组
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MyTaskActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_task" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:id="@+id/bottom_sheet"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/buildProjectButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/buildProject" />
<Button
android:id="@+id/buildTaskButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/buildTask" />
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButtionTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add" />
</android.support.design.widget.CoordinatorLayout>
我想制作检查$ all_data value = $ selected value的所有数据列表 什么是使它成为可能的最佳方法?
答案 0 :(得分:1)
试试这段代码 -
<?php
$all_data = ["admin","member","editor"];
$selected = ["admin","member"];
foreach($all_data as $value) {
$checked = in_array($value, $selected) ? 'checked="checked"' : '';
echo '<input type="checkbox" name="chk[]" value="' . $value .'" ' . $checked . '>';
}
?>