I generate json files manually this way:
$output_json = '{
"tabela1": {
"ilosc_wpisow": ';
$output_json = $output_json.'"'."$ile_wierszy_1".'",'.'
"tabela": [';
for ($i = 1; $i <= $ile_wierszy_1; $i++) {
$g = $i-1;
$szukana_wartosc_array2[$g] = str_replace(" ",'\n',$szukana_wartosc_array[$g]);
$output_json = $output_json.'
{
"bajty_przed": '.'"'.$bajty_przed_array[$g].'",
';
$output_json = $output_json.'"szukana_wartosc": '.'"'.$szukana_wartosc_array2[$g].'",
';
$output_json = $output_json.'"bajty_po": '.'"'.$bajty_po_array[$g].'",
';
$output_json = $output_json.'"nowa_wartosc": '.'"'.$nowa_wartosc_array[$g].'"
}';
if ($i!=$ile_wierszy_1) { $output_json = $output_json.','; }
}
$output_json = $output_json.'
]
},';
$output_json = $output_json.'
"tabela2": {
"ilosc_wpisow": ';
$output_json = $output_json.'"'."$ile_wierszy_2".'",'.'
"tabela": [';
for ($i = 1; $i <= $ile_wierszy_2; $i++) {
$g = $i-1;
$output_json = $output_json.'
{
"szukana_wartosc2": '.'"'.$szukana_wartosc2_array[$g].'",
';
$output_json = $output_json.'"zamien_na": '.'"'.$zamien_na_array[$g].'",
';
$output_json = $output_json.'"przesuniecie": '.'"'.$przesuniecie_array[$g].'"
}';
if ($i!=$ile_wierszy_2) { $output_json = $output_json.','; }
}
$output_json = $output_json.'
]
}
}';
Someone help me create the function json_encode? I tried in different ways to add variables to the array, but every time I have something different on the output.
Output: https://pastebin.com/f8keXaY7
json_decodeon it to see how to build it.json_encodeandjson_decode. Please post the question and expected result clearly, so that we can help you.https://www.php.net/manual/en/function.json-encode.phpThere are several examples in this documentation. Take sometime to understand and apply.