...
The next prompt is now the one where you automatically create a data.json from the DBF file, which is then displayed.
Here, I use my own development: the php4dbf library.
Can you provide me with source code to directly create the data.json using php4dbf?
{
  "records": 500,
  "ageStatistics": [
    {
      "ageGroup": "20-29",
      "count": 54
    },
    {
      "ageGroup": "30-39",
      "count": 53
    },
    {
      "ageGroup": "40-49",
      "count": 60
    },
    {
      "ageGroup": "50-59",
      "count": 63
    },
    {
      "ageGroup": "60-69",
      "count": 62
    },
    {
      "ageGroup": "70-79",
      "count": 64
    },
    {
      "ageGroup": "80-89",
      "count": 69
    },
    {
      "ageGroup": "90-99",
      "count": 75
    }
  ],
  "salaryStatistics": [
    {
      "range": "Under \u20ac25,000",
      "count": 79
    },
    {
      "range": "\u20ac25,000 - \u20ac50,000",
      "count": 82
    },
    {
      "range": "\u20ac50,001 - \u20ac75,000",
      "count": 68
    },
    {
      "range": "\u20ac75,001 - \u20ac100,000",
      "count": 97
    },
    {
      "range": "Over \u20ac100,000",
      "count": 174
    }
  ],
  "stateDistribution": [
    {
      "state": "IL",
      "count": 13
    },
    {
      "state": "MA",
      "count": 7
    },
    {
      "state": "WY",
      "count": 10
    },
    {
      "state": "ID",
      "count": 12
    },
    {
      "state": "CT",
      "count": 9
    },
    {
      "state": "WV",
      "count": 10
    },
    {
      "state": "RI",
      "count": 9
    },
    {
      "state": "HI",
      "count": 14
    },
    {
      "state": "AK",
      "count": 10
    },
    {
      "state": "IN",
      "count": 15
    },
    {
      "state": "WA",
      "count": 13
    },
    {
      "state": "NC",
      "count": 10
    },
    {
      "state": "AR",
      "count": 15
    },
    {
      "state": "MS",
      "count": 10
    },
    {
      "state": "VT",
      "count": 11
    },
    {
      "state": "NY",
      "count": 13
    },
    {
      "state": "KY",
      "count": 13
    },
    {
      "state": "LA",
      "count": 14
    },
    {
      "state": "VA",
      "count": 5
    },
    {
      "state": "DE",
      "count": 13
    },
    {
      "state": "WI",
      "count": 11
    },
    {
      "state": "FL",
      "count": 10
    },
    {
      "state": "TN",
      "count": 8
    },
    {
      "state": "KS",
      "count": 8
    },
    {
      "state": "PA",
      "count": 9
    },
    {
      "state": "CA",
      "count": 13
    },
    {
      "state": "IA",
      "count": 10
    },
    {
      "state": "ME",
      "count": 7
    },
    {
      "state": "OH",
      "count": 8
    },
    {
      "state": "NH",
      "count": 13
    },
    {
      "state": "MI",
      "count": 6
    },
    {
      "state": "OK",
      "count": 13
    },
    {
      "state": "NM",
      "count": 8
    },
    {
      "state": "SC",
      "count": 11
    },
    {
      "state": "CO",
      "count": 7
    },
    {
      "state": "MT",
      "count": 10
    },
    {
      "state": "AZ",
      "count": 8
    },
    {
      "state": "NE",
      "count": 16
    },
    {
      "state": "TX",
      "count": 7
    },
    {
      "state": "AL",
      "count": 7
    },
    {
      "state": "MN",
      "count": 8
    },
    {
      "state": "NV",
      "count": 9
    },
    {
      "state": "ND",
      "count": 6
    },
    {
      "state": "MD",
      "count": 8
    },
    {
      "state": "UT",
      "count": 9
    },
    {
      "state": "NJ",
      "count": 11
    },
    {
      "state": "OR",
      "count": 9
    },
    {
      "state": "SD",
      "count": 11
    },
    {
      "state": "GA",
      "count": 10
    },
    {
      "state": "MO",
      "count": 3
    }
  ],
  "maritalStatus": [
    {
      "status": "Married (T)",
      "count": 255
    },
    {
      "status": "Not Married (F)",
      "count": 245
    }
  ]
}
<?php
// Include the php4dbf library
include 'php4dbf.php';
// Path to the DBF file
$dbfFilePath = 'data.dbf'; // Change this to the path of your DBF file
// Open the DBF file
$dbfHandle = php4dbf_openDbf($dbfFilePath);
if (!$dbfHandle) {
  die("Error: Unable to open DBF file.");
}
// Get the number of records and fields
$totalRecords = php4dbf_numrecords($dbfHandle);
$totalFields = php4dbf_numfields($dbfHandle);
// Initialize statistics
$ageGroups = [
  '20-29' => 0, '30-39' => 0, '40-49' => 0,
  '50-59' => 0, '60-69' => 0, '70-79' => 0,
  '80-89' => 0, '90-99' => 0,
];
$salaryRanges = [
  'Under €25,000' => 0, '€25,000 - €50,000' => 0,
  '€50,001 - €75,000' => 0, '€75,001 - €100,000' => 0,
  'Over €100,000' => 0,
];
$states = [];
$maritalStatus = ['T' => 0, 'F' => 0];
// Loop through each record
for ($i = 1; $i <= $totalRecords; $i++) {
  $record = php4dbf_get_record_with_names($dbfHandle, $i);
  if (!$record) {
    continue; // Skip if the record is invalid
  }
  // Age Statistics
  $age = isset($record['AGE']) ? (int)$record['AGE'] : 0;
  if ($age >= 20 && $age <= 29) $ageGroups['20-29']++;
  elseif ($age >= 30 && $age <= 39) $ageGroups['30-39']++;
  elseif ($age >= 40 && $age <= 49) $ageGroups['40-49']++;
  elseif ($age >= 50 && $age <= 59) $ageGroups['50-59']++;
  elseif ($age >= 60 && $age <= 69) $ageGroups['60-69']++;
  elseif ($age >= 70 && $age <= 79) $ageGroups['70-79']++;
  elseif ($age >= 80 && $age <= 89) $ageGroups['80-89']++;
  elseif ($age >= 90) $ageGroups['90-99']++;
  // Salary Statistics
  $salary = isset($record['SALARY']) ? (float)$record['SALARY'] : 0;
  if ($salary < 25000) $salaryRanges['Under €25,000']++;
  elseif ($salary <= 50000) $salaryRanges['€25,000 - €50,000']++;
  elseif ($salary <= 75000) $salaryRanges['€50,001 - €75,000']++;
  elseif ($salary <= 100000) $salaryRanges['€75,001 - €100,000']++;
  else $salaryRanges['Over €100,000']++;
  // State Distribution
  $state = isset($record['STATE']) ? $record['STATE'] : 'Unknown';
  if (!isset($states[$state])) {
    $states[$state] = 0;
  }
  $states[$state]++;
  // Marital Status
  $marital = isset($record['MARRIED']) ? $record['MARRIED'] : 'F';
  if (isset($maritalStatus[$marital])) {
    $maritalStatus[$marital]++;
  }
}
// Close the DBF file
php4dbf_close($dbfHandle);
// Prepare JSON data
$jsonData = [
  'records' => $totalRecords,
  'ageStatistics' => array_map(function ($group, $count) {
    return ['ageGroup' => $group, 'count' => $count];
  }, array_keys($ageGroups), $ageGroups),
  'salaryStatistics' => array_map(function ($range, $count) {
    return ['range' => $range, 'count' => $count];
  }, array_keys($salaryRanges), $salaryRanges),
  'stateDistribution' => array_map(function ($state, $count) {
    return ['state' => $state, 'count' => $count];
  }, array_keys($states), $states),
  'maritalStatus' => [
    ['status' => 'Married (T)', 'count' => $maritalStatus['T']],
    ['status' => 'Not Married (F)', 'count' => $maritalStatus['F']],
  ],
];
// Write JSON data to a file
file_put_contents('data.json', json_encode($jsonData, JSON_PRETTY_PRINT));
echo "JSON file has been created successfully: data.json";