Use explode
instead of split
. Your code should look like this :
$opt = explode("_",$key);
if($opt[0]=="id" && $val!="0" && $val!=""){
some queries
$shuffle=explode("_",$_POST['all_'.$i]);
Documentation : http://fr2.php.net/explode
Вопрос
I know that there are several questions about this issue, but this is a particullar case... In the following code (in the the first and the last line) I have to replace split with preg_split, but I think something else needs to be changed too.
Please tell me what should I change in the code for it to work, and the theory behind this change, i.e. the gereral idea behind switching between split and preg_split. The code which needs the transition is:
$opt = split("_",$key);
if($opt[0]=="id" && $val!="0" && $val!=""){
some queries
$shuffle=split("_",$_POST['all_'.$i]);
Решение
Use explode
instead of split
. Your code should look like this :
$opt = explode("_",$key);
if($opt[0]=="id" && $val!="0" && $val!=""){
some queries
$shuffle=explode("_",$_POST['all_'.$i]);
Documentation : http://fr2.php.net/explode
Другие советы
PHP is in the process of dropping an older POSIX-compatible regex extension in favour of the newer PCRE extension. This means that older functions like split()
and ereg()
will be removed in time.
The PCRE equivalent for split()
is preg_split()
, which has a modified syntax. For your code you'd use:
$opt = preg_split("/_/",$key);
However, a Regex function is a heavyweight tool and isn't required here. You just need explode()
, like this:
$opt = explode("_",$key);