1)我无法相交数组:2)我无法使用键获取关联 POST 数组的值
$adbcols=Array ( [tcid] => tcid .... array containing database column names
$aformval=Array ( ['tcbcheck'] => on ['tcprice'] => 100 ['tctitf'] => 01
.. 包含 POST 数据的数组
function amatchfnc($a, $b) {
if ($a==$b){ return 0; }
return ($a>$b) ? 1:-1;
} // function amatchfnc($a, $b)
foreach ($_POST as $apie=>$aformval ) {
$aresf=array_intersect_ukey($aformval,$adbcols,"amatchfnc");
} }
更完整的代码:
foreach ($_POST as $apie=>$aformval ) {
echo "<br><br> apie:"; print_r($apie);
echo "<br><br> aformval:"; print_r($aformval); //prints, also aformval[tcbcheck]
echo "<br><br> aformval[tcbcheck]".$aformval['tcbcheck']; //gives empy line
if(isset($_SESSION['vcurprcode'])) { $aformval['tcfkcode']=$_SESSION['vcurprcode'];}
$aresf=array_intersect_ukey($aformval,$adbcols,"amatchfnc");
echo "<br><br><br> print_r(aresf)="; print_r($aresf);
insertvalues($aresf,$adbcols, $conn, $vdbname, $tprice);
} //foreach ($_POST as $apie )
来自 prin_r 的输出,回显:
> apie:mon01
>
> aformval:Array ( ['tcbcheck'] => on ['tcprice'] => 100 ['tctitf'] =>
> 01 ['tcdatefromto'] => priceFrom20140101To20140131 ['tcbset'] => 3
> ['tcbsettit'] => month ['tcdesc'] => )
>
> aformval[tcbcheck]connectedstr02=SHOW COLUMNS FROM
> gintare_calendar.tapris3
> 0. ShowCol. Selected successfully gintare_calendar.tapris3
>
>
> print_r(adbcols)=Array ( [tcid] => tcid [tcdateacc] => tcdateacc
> [tcLdateacc] => tcLdateacc [tcdatecr] => tcdatecr [tcdesc] => tcdesc
> [tcbset] => tcbset [tcbsettit] => tcbsettit [tcbconf] => tcbconf
> [tcbcheck] => tcbcheck [tcdurup] => tcdurup [tcdurlow] => tcdurlow
> [tctitf] => tctitf [tcdate] => tcdate [tcdatefromto] => tcdatefromto
> [tccur] => tccur [tcbcur] => tcbcur [tcprice] => tcprice [tcbdisc] =>
> tcbdisc [tcfkdisc] => tcfkdisc [tcdisc] => tcdisc [tcdiscper] =>
> tcdiscper [tcpricedisc] => tcpricedisc [tcpurpose] => tcpurpose
> [tcdescpric] => tcdescpric [tcbsavset] => tcbsavset [tcprtit] =>
> tcprtit [tcfkcode] => tcfkcode [tcvauk] => tcvauk [tcdatefrom] =>
> tcdatefrom [tcdateto] => tcdateto [tcpryear] => tcpryear [tcprmonth]
> => tcprmonth [tcprweek] => tcprweek [tcprday] => tcprday )
>
>
> abefore intersect print_r(aformval)=Array ( ['tcbcheck'] => on
> ['tcprice'] => 100 ['tctitf'] => 01 ['tcdatefromto'] =>
> priceFrom20140101To20140131 ['tcbset'] => 3 ['tcbsettit'] => month
> ['tcdesc'] => [tcbcheck] => checked [tcfkcode] => 1 )
>
> print_r(aresf)=Array ( [tcbcheck] => checked [tcfkcode] => 1 )
$aresf
应该包含所有$aformal
值。我进行交集只是为了检查 aref 的列名是否与数据库的列名一致。$adbcols 我从数据库模式中获取。
我发布的 HTML 文件包含以下段落:
<input type= "text" name="mon01['tcprice']" value="<?php echo $mon01['tcprice']; ?>" " >
<input type="range" name="mon01[range]" min="0" max="1000" >
<input type="hidden" class="mon" name="mon01['tctitf']" value="01"; " size="1" >
<input type="hidden" class="mon" name="mon01['tcdatefromto']"
value="priceFrom20140101To20140131"; " size="1" >
<input type="hidden" class="mon" name="mon01['tcbset']" value="3"; " size="1" >
<input type="hidden" class="mon" name="mon01['tcbsettit']" value="month"; " >
<textarea cols="50" rows="3" name="mon01['tcdesc']"
value="<?php echo $mon01['tcdesc']; ?>" > </textarea>
通常数组交集有效。下面的例子是一些数组:
<?php
$af=array( "a"=>"a","c"=>"c", "e"=>"e" );
$ad=array( "a"=>"a","b"=>"b","c"=>"c","d"=>"d", "e"=>"e" );
$af=array_intersect_ukey($af,$ad,"amatchfnc");
echo "<br> print_r(af)="; print_r($aresf);
?>
给出: print_r(aresf)=Array ( [a] => a [c] => c [e] => e )
但是如果我尝试与 POST 数组 $aformval 相交,我会得到奇怪的结果。如何与 POST 数组相交?