有人可以告诉我如何从 MySQL 查询创建数组吗?
数组应该是这样的:
<?php
$testLocs = array(
'1' => array( 'info' => '1. New Random info and new position', 'lat' => 45345345, 'lng' => 44.9634 ),
'2' => array( 'ino' => '1. New Random info and new position', 'lat' => 686788787, 'lng' => 188.9634),
'3' => array( 'info' => '1. New Random info and new position', 'lat' => 88888, 'lng' => 144.9634),
'4' => array( 'info' => '1. New Random info and new position', 'lat' => 666666, 'lng' => 144.964 )
);
echo json_encode($testLocs);
exit();
?>
info
的text 和lat
和lng
的numbers 是MySQL $行
。
如有任何帮助,我们将不胜感激。
最佳答案
阅读manual
取自 PHP 手册的例子
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
关于php - 从 MySQL 查询构建数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31811680/