Jayesh KR Jayesh KR - 1 year ago 54
PHP Question

How to convert an associative array into a simple array in php?

I have this:


array(2) { [0]=> string(3) "NBA" [1]=> string(7) "MGNREGS" }


I need it as
["NBA","MGNREGS"]


Can anyone help me with this.

Thanks in advance.

Answer Source

For which purpose do you need the array?

If you want to use JSON data, just try to call json_encode on the array:

$array = array('NBA', 'MGNREGS');
var_dump($array);
print json_encode($array);

Output:

array(2) { 
  [0]=> string(3) "NBA"
  [1]=> string(7) "MGNREGS"
}

["NBA","MGNREGS"]