-3

数据库

**username**
admin

**ref**
a:2:{i:0;s:5:"Facebook";i:1;s:6:"Forum";}

PHP

$query = "SELECT * FROM users WHERE username='admin'";
echo json_encode($query);

我如何反序列化 Ref 并传递给 echo json_encode($query); ?

4

1 回答 1

1

你可以这样做

$query = "SELECT * FROM users WHERE username='admin'";

$rec    =   mysqli_query($query);
$row    =   mysql_fetch_assoc($rec);

$ref    =   unserialize($row['ref']);

$row['ref'] =   $ref;

echo json_encode($row);

或者你也可以这样做

$data   =   array();
$data['admin']  =   $row['admin'];
$data['ref']    =   unserialize($row['ref']);

echo json_encode($data);
于 2013-03-14T11:04:25.783 回答