Heim >Backend-Entwicklung >PHP-Tutorial >php使用post数组的键值创建同名变量并赋值的方法_PHP教程

php使用post数组的键值创建同名变量并赋值的方法_PHP教程

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 09:58:08845Durchsuche

php使用post数组的键值创建同名变量并赋值的方法

 本文实例讲述了php使用post数组的键值创建同名变量并赋值的方法。分享给大家供大家参考。具体如下:

这段代码可以自动根据post数组的键值创建同名变量,这个功能使用非常方便,不用提前声明变量

1

2

3

4

5

6

7

8

9

10

11

$expected=array('username','age','city','street');

foreach($expected as $key){

if(!empty($_POST[$key])){

${key}=$_POST[$key];

}

else{

${key}=NULL;

}

}

?>

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/979232.htmlTechArticlephp使用post数组的键值创建同名变量并赋值的方法 本文实例讲述了php使用post数组的键值创建同名变量并赋值的方法。分享给大家供大家参考...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn