douli1306 2011-10-31 14:58
浏览 35
已采纳

PHP在一个数组中内爆一个数组

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.

  • 写回答

2条回答 默认 最新

  • dtxw20878 2011-10-31 15:04
    关注

    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
    $data =array( 'a' => array( 1,2,3 ), 'c' => array( 4,5,6 ) );
    foreach($data AS $key => $value) {
    if(is_array($value)) 
    { 
      $data[ $key ] = implode("|", $value); 
    }
    }
    var_dump( $data );
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件