Converting JSONL to Array with PHP

PHPServer Side ProgrammingProgramming

The json_decode function can be used as shown below −

json_decode($json_string_that_needs_to_be_converted, true);

The below lines of code can be used to convert JSONL to array format −

$json_string = '["m@gmail.com","p@gmail.com","q@gmail.com"]';
$array_of_data=json_decode($json_string);

An alternate is to use the below code, wherein the way json_string has been defined changes −

Example

$json_string = "[\"m@gmail.com\",\"p@gmail.com\",\"q@gmail.com\"]";
$array_of_data=json_decode($json_string);

Output

This will produce the following output −

Array("m@gmail.com","p@gmail.com","q@gmail.com")
raja
Published on 06-Apr-2020 12:00:39
Advertisements