This article mainly introduced the PHP simple construction JSON multidimensional array method, combined with the instance form analysis PHP database query result JSON format conversion operation skill, needs the friend can refer to the next
This article describes a simple way to construct a JSON multidimensional array in PHP. Share to everyone for your reference, as follows:
PHP constructs JSON multidimensional arrays is actually very simple
The following is a list of PHP code that serializes the MYSQLI query result array to JSON:
$res [' result '] = "OK", $res [' msg '] = ' login '; $res [' fileinfo '] = array (); while ($stmt->fetch ()) { $fileinfo [' Fileid '] = $fileid; $fileinfo [' name '] = $name; $fileinfo [' fujianname '] = $fujianname; Array_push ($res [' FileInfo '], $fileinfo);} echo Json_encode ($res);
The output string is as follows:
Copy the Code code as follows:
{"Result": "OK", "MSG": "Login", "FileInfo": [{"Fileid": 113, "name": "Jishumingcheng", "Fujianname": "Test.txt_test_ 20161005214223 "},{" Fileid ":", "name": "Wodejishu", "Fujianname": "test.txt_test2_20161005230610"}]}