Heim > Artikel > Backend-Entwicklung > CI框架,源代码一次性判断获取postget数据是否有某个字段值为空方法 源代码索拉卡 源代码下载 lol源代
一、以下是CI框架
1、把所有的要接收的字段放在数组中
例:
我要接收:id,name,age,mobile 等字段
<span>$req</span> = <span>array</span>('id','name','age','mobile');
2、for循环判断即可
<span>1</span><span>for</span>(<span>$i</span> = 0;<span>$i</span> count(<span>$req</span>);<span>$i</span> ++<span> ){ </span><span>2</span><span>$j</span> = <span>$this</span>->load->get_post(<span>$req</span>[<span>$i</span>],<span>true</span><span>); </span><span>3</span><span>if</span>(<span>empty</span>(<span>$j</span><span>)) </span><span>4</span><span>exit</span>(<span>$req</span>[<span>$i</span>].' 为空'<span>); </span><span>5</span><span>$data</span>[<span>$i</span>] = <span>$j</span><span>; </span><span>6</span><span>} </span><span>7</span><span>print_r</span>(<span>$data</span>);
二、源代码判断方法(就不废话了,直接上代码)
<span>$req</span> = <span>array</span>('id','name','age','mobile'<span>); </span><span>for</span>(<span>$i</span> = 0;<span>$i</span> count(<span>$req</span>);<span>$i</span> ++<span> ){ </span><span>$j</span> = <span>$_POST</span>[<span>$req</span>[<span>$i</span><span>]]; </span><span>if</span>(<span>empty</span>(<span>$j</span><span>)) </span><span>exit</span>(<span>$req</span>[<span>$i</span>].' 为空'<span>); </span><span>$data</span>[<span>$i</span>] = <span>$j</span><span>; } </span><span>print_r</span>(<span>$data</span>);
结束语:
其实CI框架与源代码都可以用源代码这种方法(二),但是为了验证安全性,使用第一种方案而已,以上调用的其他方法是php自带的,哪个方法不懂,可以查一下PHP 帮助文档(大神忽略)
以上就介绍了CI框架,源代码一次性判断获取postget数据是否有某个字段值为空方法,包括了post,源代码方面的内容,希望对PHP教程有兴趣的朋友有所帮助。