PHP 在数组中内爆数组
我正在破解表达式引擎,以允许在成员个人资料表单中使用多选、单选和复选框自定义字段类型。
解析表单并提交更新查询的模型将表单中的所有值提交到一个数组变量 - '$data' 中。 $data 中的数组值之一是来自多选字段类型的另一个数组 - 因此当提交查询时它会返回错误...
Unknown column 'Array' in 'field list'
UPDATE `apcims_member_data` SET `m_field_id_1` = '', `m_field_id_2` = Array WHERE `member_id` = '2'
因此我需要在执行 SQL 之前内爆 $data 数组中的所有数组。
是否有类似...
foreach($data AS $value) {
if($value(is_array)) { $value = implode("|", $value); }
}
...然后重新插入原始索引或位置的功能?
任何帮助表示赞赏。
I'm hacking Expression Engine to enable the use of multiselect, radio and checkbox custom field types within the members profile form.
The model which parses the form and commits the update query submits all values from the form in one array variable - '$data'. One of the array values within $data is another array coming from a multiselect field type - so when the query is submitted it returns an error...
Unknown column 'Array' in 'field list'
UPDATE `apcims_member_data` SET `m_field_id_1` = '', `m_field_id_2` = Array WHERE `member_id` = '2'
So I need to implode any arrays within the $data array before the SQL is executed.
Is there a function something like...
foreach($data AS $value) {
if($value(is_array)) { $value = implode("|", $value); }
}
...then reinsert at the original index or position?
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你们非常接近。您正在寻找的方法是
is_array
。另外,foreach
可以为您提供索引和值,以便您可以自己更新数组中的值。You were pretty close. The method you are looking for is
is_array
. Also,foreach
, can give you the index as well as the value so that you can update the value in the array yourself.这最适用于带有匿名函数的新映射函数(自 PHP 5.3 起)
This is best use for new mapping function with anonymous function (since PHP 5.3)