一般从数据循环出来的选框要处理是否被选中都是使用IF去判断,结果造成代码一堆,速度过慢。
我做了一个闭包分享给大家,希望对大家有用。
代码:
- function ifNumExists($numList,$key) {
- $return = false;
- $arraylist = split(",", $numList);
- $Length = count($arraylist)-1; //最后一个数组结果为空,所以应当减去。
- for ($i=0;$i
- if ($arraylist[$i] == $key) {
- $return = true;
- }
- }
- return $return;
- }
使用方法:
- ifNumExists(数组,当前单选框对应ID)
表结构:
单选框循环表(A):
id class
1 类别1
2 类别2
3 类别3
4 类别4
单选值存放表(B):
id classid
1 1,2,3,
2 2,3,4,
3 1,2,
当循环表A,判断是否当前input是否被选中,那么我们就可以使用
ifNumExists(classid,表Aid),返回的结果为true或者false,根据返回的结果我们给input增加或者不增加 checked="checked"。
如:
- if (ifNumExists(classid,$value['id'])) {
- $list = $list."".$value['class']." ";
- }else{
- $list = $list."".$value['class']." ";
- }
- return $list;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools
