多维数组作为变量保存在 dB 中
Multidimensional Array as Variables to save in dB
我有一个多维数组
output_querys = array(2) { [0]=> array(5) { ["ID"]=> string(1) "2" ["Code"]=> string(6) "AWS001" ["BCode"]=> string(4) "B001" ["Des"]=> string(4) "loan" ["subCat"]=> string(3) "SWA" } [1]=> array(5) { ["ID"]=> string(1) "4" ["Code"]=> string(6) "AWS002" ["BCode"]=> string(4) "B002" ["Des"]=> string(3) "tax" ["subCat"]=> string(3) "PJA" } }
我想把它取到一个变量中,然后保存到dB.I中,相关问题中提到的所有方法都试过了,都没有用。
我得到的错误
1.trying 非对象
2.Illegal 字符串偏移量
我想做的是
foreach($output_querys as $output_query){
$Pv_ID = $output_query->ID;
$Pv_Code = $output_query->Code;
$Pv_Description = $output_query->Des;
$data_final = array(id => $Pv_ID, code => $Pv_Code, des => $Pv_Description);
}
db->insert(abc, $data_final);
这里有什么问题??即使我尝试使用 json 编码,仍然显示“非法字符串偏移”
$Pv_ID= json_decode($output_query['ID']);
$Pv_Code = json_encode($output_query['Code'],true);
$Pv_Description = json_encode($output_query['Des'],true);
我试过你给的数组和代码
<?php
$output_querys = array(
0 => array(
"ID" => "2",
"Code" => "AWS001",
"BCode" => "B001",
"Des" => "loan",
"subCat" => "SWA"
),
1 => array(
"ID" => "4",
"Code" => "AWS002",
"BCode" => "B002",
"Des" => "tax",
"subCat" => "PJA"
)
);
foreach($output_querys as $output){
print_r($output['Code']); echo "\n";
}
?>
我这边工作正常。 Here's the working example
我认为你也需要这样做,如果你想 1 乘 1 地插入然后将插入移动到 foreach 循环中
foreach($output_querys as $output_query){
$Pv_ID = $output_query->ID;
$Pv_Code = $output_query->Code;
$Pv_Description = $output_query->Des;
$data_final = array(id => $Pv_ID, code => $Pv_Code, des => $Pv_Description);
db->insert(abc, $data_final);
}
我有一个多维数组
output_querys = array(2) { [0]=> array(5) { ["ID"]=> string(1) "2" ["Code"]=> string(6) "AWS001" ["BCode"]=> string(4) "B001" ["Des"]=> string(4) "loan" ["subCat"]=> string(3) "SWA" } [1]=> array(5) { ["ID"]=> string(1) "4" ["Code"]=> string(6) "AWS002" ["BCode"]=> string(4) "B002" ["Des"]=> string(3) "tax" ["subCat"]=> string(3) "PJA" } }
我想把它取到一个变量中,然后保存到dB.I中,相关问题中提到的所有方法都试过了,都没有用。 我得到的错误 1.trying 非对象 2.Illegal 字符串偏移量
我想做的是
foreach($output_querys as $output_query){
$Pv_ID = $output_query->ID;
$Pv_Code = $output_query->Code;
$Pv_Description = $output_query->Des;
$data_final = array(id => $Pv_ID, code => $Pv_Code, des => $Pv_Description);
}
db->insert(abc, $data_final);
这里有什么问题??即使我尝试使用 json 编码,仍然显示“非法字符串偏移”
$Pv_ID= json_decode($output_query['ID']);
$Pv_Code = json_encode($output_query['Code'],true);
$Pv_Description = json_encode($output_query['Des'],true);
我试过你给的数组和代码
<?php
$output_querys = array(
0 => array(
"ID" => "2",
"Code" => "AWS001",
"BCode" => "B001",
"Des" => "loan",
"subCat" => "SWA"
),
1 => array(
"ID" => "4",
"Code" => "AWS002",
"BCode" => "B002",
"Des" => "tax",
"subCat" => "PJA"
)
);
foreach($output_querys as $output){
print_r($output['Code']); echo "\n";
}
?>
我这边工作正常。 Here's the working example
我认为你也需要这样做,如果你想 1 乘 1 地插入然后将插入移动到 foreach 循环中
foreach($output_querys as $output_query){
$Pv_ID = $output_query->ID;
$Pv_Code = $output_query->Code;
$Pv_Description = $output_query->Des;
$data_final = array(id => $Pv_ID, code => $Pv_Code, des => $Pv_Description);
db->insert(abc, $data_final);
}