M
M
misc12015-07-11 14:47:55
PHP
misc1, 2015-07-11 14:47:55

How can json be "converted"?

Hello, there is a json like:
[{"PAN":"1234"},{"PAN":"123456789"}]
Need to get:
["1234","123456789"]
How can this be done in php?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2015-07-11
@misc1

$obj = json_decode($json);
$result=array();
foreach ($obj as $o) $result[]=$o["PAN"];
echo json_encode($result);

N
Nazar Mokrinsky, 2015-07-11
@nazarpc

json_encode(
    array_column(
        json_decode('[{"PAN":"1234"},{"PAN":"123456789"}]', true),
        'PAN'
    )
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question