从php键值数组中删除字符

时间:2016-11-07 17:42:45

标签: php arrays

enter image description here

这是我现在拥有的数组。我想删除[0] =>中的随机开括号[“A100”以及[4]中的随机右括号=> “B11”] ....我尝试过使用:

    foreach($list as $key=>$value)
{
    **//its suppose to be the same array that is $list not a new array $array**
    $list[$key]=str_replace("[","",$value);
}

$ list是包含图片元素的数组。它似乎没有删除括号..我做错了什么?

**更新:**

我从localstorage获取数组,通过post发送到另一个php,我抓住了值并爆炸到一个名为$ list的数组。

    $(function(){
    $('#fbtn').click(function(){
    $.ajax({
        url: 'FactorAnalysis.php',
        type: 'POST', // GET or POST
        data: {data: localStorage.getItem('reportArray')}, // will be in $_POST on PHP side
        success: function(data) { // data is the response from your php script
            // This function is called if your AJAX query was successful
            alert("Response is"+ data);
        },
        error: function() {
            // This callback is called if your AJAX query has failed
            alert("failed");
        }
    });
});

});

输出到div的localStorage告诉我: enter image description here

所以这里我通过ajax调用发送数据:

      $list = array();

       $list = explode(',',$_POST['data']);

^然后在另一个php(FactorAnalysis.php)中我得到数组并爆炸到数组$ list。

1 个答案:

答案 0 :(得分:0)

试试这个

$list = explode(',',$_POST['data']);

代替

{{1}}