将包含整数的变量解构为数组
Deconstruct an variable containing integers into an array
我是 PHP 的新手,我似乎遇到了障碍 code.I 有一个变量,其中包含由 space 分隔的数字序列。我打算将每个数字作为单独的记录提交到数据库中。我的问题是如何将变量解构为单个整数,以便将每个整数作为新记录提交。这是我的代码:
foreach ($domains as $domain)
{
$clicked_domains = array($form_entry->{"domain_$domain->id"});
if($clicked_domains){
foreach($clicked_domains as $final_selection){
if ($final_selection != 0){
echo $final_selection." "; // $final_selection now has the value of 17 20 12
}
}
}
}
我现在想从 $final_selection 中提取每个整数(不包括 spaces)以提交给数据库
我是 PHP 的新手,我似乎遇到了障碍 code.I 有一个变量,其中包含由 space 分隔的数字序列。我打算将每个数字作为单独的记录提交到数据库中。我的问题是如何将变量解构为单个整数,以便将每个整数作为新记录提交。这是我的代码:
foreach ($domains as $domain)
{
$clicked_domains = array($form_entry->{"domain_$domain->id"});
if($clicked_domains){
foreach($clicked_domains as $final_selection){
if ($final_selection != 0){
echo $final_selection." "; // $final_selection now has the value of 17 20 12
}
}
}
}
我现在想从 $final_selection 中提取每个整数(不包括 spaces)以提交给数据库