php – 变量变量
发布时间:2020-12-13 21:27:47 所属栏目:PHP教程 来源:网络整理
导读:如何在for循环中创建变量? 这是循环: for ( $counter = 1; $counter = $aantalZitjesBestellen; $counter ++) {} 在这个循环中我想为每次传递创建一个变量$seat,但它必须增加如此.第一次通过它应该是$seat1 = $_POST [‘seat’$aantalZitjesBestellen],下
如何在for循环中创建变量?
这是循环: for ( $counter = 1; $counter <= $aantalZitjesBestellen; $counter ++) { } 在这个循环中我想为每次传递创建一个变量$seat,但它必须增加如此.第一次通过它应该是$seat1 = $_POST [‘seat’$aantalZitjesBestellen],下次通过时:$seat2 = $_POST [‘seat’$aantalZitjesBestellen]等等. 所以最后它应该是: $seat1 = $_POST['seat1']; $seat2 = $_POST['seat2']; 等等. 所以$_POST的变量和内容应该是动态的. 解决方法
首先,我会使用一个数组,除非我遗漏了一些东西.像$seat1,$seat2等变量往往具有更少的实用性,并且比使用数组更加麻烦.
话虽如此,请使用以下语法: for ( $counter = 1; $counter <= $aantalZitjesBestellen; $counter ++) { $key = 'seat' . $counter; $$key = $_POST[$key]; } 最后,PHP有一个内置函数,用于将数组键提取到符号表中: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |