我在 PHP 方面没有经验,所以我需要你的帮助。如果我可以这样说,我想从两个数组中创建。基本上,我想以此为基础:
[{"Naziv":"Nemanja","duzina":"45.475","sirina":"23.423"},{"Naziv":"Aleksandar","duzina":"45.427","sirina":"21.124 "}]
像这样:
[{"Naziv":"Nemanja","duzina":["45.475","23.423"]},{"Naziv":"Aleksandar","duzina":["45.427","21.124"]}]
这是我的PHP:
// Create connection
$con = mysqli_connect($host, $user, $pwd, $db);
// Check connection
if(mysqli_connect_errno($con)) {
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
// query the application data
$sql = "SELECT Naziv,duzina,sirina FROM lokacije";
$result = mysqli_query($con, $sql);
// an array to save the application data
$rows = array();
// iterate to query result and add every rows into array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$rows[] = $row;
}
// close the database connection
mysqli_close($con);
// echo the application data in json format
echo json_encode($rows);