php - How do I remove some of the square brackets that wrap a JSON array -
i trying workout how format brackets wrapping json array. pulling data array out of database using code.
 $result = mysqli_query($con,"select * table");  $column = array();   while ($row = mysqli_fetch_array($result))   {    $column[] = array(array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5]),$row[3],$row[2],$row[0]);   }   once converted json array prints screen in format. need first square brackets remain need swap second set of brackets (\').
var myvar = [ [["22","mike"," 151.1272","-33.9324","learning fish","08\/14\/13"],"-33.93024"," 151.12896172","22"], [["23","mike"," -2.09875","51.44501","learning french","08\/04\/13"],"51.44501"," -2.09775","23"], [["24","mike"," -2.16375","51.44823019014051","programming","08\/05\/13"],"51.451"," -2.1675","24"], ];   so array should more this.
var myvar = [ ['"22","mike"," 151.12","-33.934","learning fish","08\/14\/13"',"-33.94"," 151.12","22"], ['"23","mike"," -2.095","51.41","learning french","08\/04\/13"',"51.41"," -2.095","23"], ['"24","mike"," -2.165","51.41","programming","08\/05\/13"',"51.44851"," -2.1675","24"],  ];   the reason need array in format can pass data google maps function expects array have 4 columns.
i have worked out can remove brackets function this, problem removes brackets , need external brackets;
$js_array = str_replace(array('[', ']'), '\'', htmlspecialchars(json_encode($column), ent_noquotes));   how keep external brackets , remove internal brackets? if have not given enough information or should add more details let me know.
thanks
how making array way need in first place? instead of:
$column[] = array(     array(         $row[0],         $row[1],         $row[2],         $row[3],         $row[4],         $row[5]     ),     $row[3],     $row[2],     $row[0] );   do this:
$column[] = array(     $row[0] . $row[1] . $row[2] . $row[3] . $row[4] . $row[5],     $row[3],     $row[2],     $row[0] );      
Comments
Post a Comment