0
I have the following JSON structure
{
"trophy_name_XPT001": "Text Name 01",
"trophy_desc_XPT001": "Text Desc 01",
"throw.except.und": "Error",
"nav_bunt_852": "Zoom Out",
"trophy_name_BHTLN": "Text Name 02",
"trophy_desc_BHTLN": "Text Desc 02",
"trophy_name_XPT020": "Text Name 03",
"trophy_desc_XPT020": "Text Desc 03",
"abc_gama_opt": "Text Random",
"inpt.hover.ali": "11.02.22.456-896",
"trophy_name_OPB852": "Text Name 04",
"trophy_desc_OPB852": "Text Desc 04",
"trophy_name_XPTHJN": "Text Name 06",
"trophy_desc_XPTHJN": "Text Desc 06",
"trophy_name_XPT002": "Text Name 008*01",
"trophy_desc_XPT002": "Text Desc 008*01",
"nav_admin": "89652"
}
I need to filter only the data that contains trophy_name_...
and trophy_desc_...
and use a foreach to iterate and merge the same code into a single array
At the moment the code is this
<?php
$json = json_decode(file_get_contents("texts.json"));
foreach ($json as $key => $value) {
if (preg_match_all("/trophy_(name|desc)_(.*.)/", $key, $matches)) {
$type = $matches['1']['0'];
$code = $matches['2']['0'];
}
}
?>
And I need a way out in this style
/* Objetivo
Codigo: XPT001 | Nome: Text Name 01 | Descrição: Text Desc 01
Codigo: BHTLN | Nome: Text Name 02 | Descrição: Text Desc 02
....
Codigo: XPT002 | Nome: Text Name 008*01 | Descrição: Text Desc 008*01
*/
I don’t know if the preg_match_all
is the best way to do it
Perfect, thank you very much!
– AndreLps