Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lat4732's avatar
Level 12

How to convert a result from API to a specific format

Hello!

I want to convert this

visualization1

into this

visualization2

with pure PHP. How can I do that? The only thing that is confusing me is how to reformat the array. The request to the API and the response handling is something I can do. But I want to format the response to the exact same way as the first photo. Any ideas?

0 likes
5 replies
click's avatar
$output = array_pluck($input, 'price', 'id'); 

// actual output: 
echo json_encode($output);
1 like
martinbean's avatar

@laralex Use the data mapper pattern if you want to convert one representation of something, to a different representation.

Please or to participate in this conversation.