Y.Hewa Y.Hewa - 1 month ago 6
PHP Question

remove character from php key value array

enter image description here

This is the array i have right now. I want to remove the random open bracket in the [0] => ["A100" and also the random close bracket in [4] => "B11"] ....I ve tried using :

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 being the array that contains the pictured elements. It doesnt seem to remove the brackets.. Am I doing something wrong?

**UPDATE: **

Im getting the array from a localstorage sending it through post to another php where i catch the value and explode to a array called $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");
}
});
});


});

the localStorage outputted to a div shows me :
enter image description here

so here im sending the data through a ajax call:

$list = array();

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


^ then in another php (FactorAnalysis.php) i get the array and explode to array $list.

Answer

Try this

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

instead

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