我有一个关于显示另一个数组的数组中的变量的问题。以下是var_dump()
变量$_POST
的示例。正如你所看到的,我有一个数组......和该数组中的另一个数组......以及该数组中的另一个数组..我实际上需要每个层中的一个变量。
Array(
[type] => note
[date_time] => 17-01-01
[initiated_from] => admin
[initiated_by] => admin
[list] => 0
[note] => THIS IS A TEST
[contact] => Array
(
[id] => 250
[email] => TEST@TESTING.COM
[first_name] => TEST
[last_name] => McTESTER
[phone] => (777)777-7777
[ip] => 0.0.0.0
[tags] => buyer, requote, followup1, delete
[fields] => Array
(
[3] => TESTER@TESTER.com
[5] => TESTING TESTER
[10] => STATE
[11] => CITY
[12] => COUNTY
[6] => PHONE NUMBER
[8] => www.test.com
[9] => MORE TESTS
)
这是我尝试的代码。
$sql_note="INSERT INTO customer_notes(customer_email,note,added_by,note_date) VALUES('$_POST[contact][email]','$_POST[note]','$_POST[contact][fields][3]','$note_date')";
(忽略$note_date
)所以这些是我想要的三件事......
$_POST[note]
$_POST[contact][email]
$_POST[contact][fields][3]
我得到第一个就好了,但我得到了ARRAY[EMAIL]
和ARRAY[FIELDS][3]
答案 0 :(得分:1)
您错误地使用了variable expansion:
$foo = array();
$foo['one']['two'] = 'OK';
echo "Value is $foo[one][two]\n"; // Value is Array[two]
echo "Value is {$foo[one][two]}\n"; // Value is OK
......在错误的工作中。您的查询应如下所示:
$sql_note = "INSERT INTO customer_notes(customer_email, note, added_by, note_date)
VALUES (?, ?, ?, ?)";
...值应该在数组中传递。将原始不受信任的数据注入SQL代码非常麻烦,并且会导致SQL注入漏洞。请查看数据库库的文档。