(go) using Json,phpjson in the PHP language
Original:
Http://www.ruanyifeng.com/blog/2011/01/json_in_php.html
------------------------------------------------------------------------
Author: Ruan Yi Feng
Date: January 14, 2011
Currently, JSON has
How to use JSON in the PHP language
Starting with version 5.2, PHP native provides the Json_encode () and Json_decode () functions, which are used for encoding, which is used for decoding.
First, Json_encode ()
This function is primarily used to
Recently in the front-end docking, encountered a problem, the front-end required to return the data format is left, but I returned through the Json_encode data format is the right Note: The data format from "[]" (array) into "{}" (object)Google,
First, the concept:1, natural sorting method: that is, according to the natural number of the size of the order, such as "10>2";2, the computer standard sorting method: is to compare by character, sort, for example "2>10" (because the first bit 2>1);
Currently, JSON has become one of the most popular formats for data interchange, with almost all the APIs of the major websites supporting it.I wrote a "data type and JSON format" to explore its design ideas. Today, I want to summarize the PHP
Before I wrote a simple example of PHP return JSON data, just surf the internet, suddenly found an article, also introduced JSON, quite detailed, it is worth reference. The contents are as follows
Starting with version 5.2, PHP native provides Json_
Before I wrote a simple example of PHP return JSON data, just surf the internet, suddenly found an article, also introduced JSON, quite detailed, it is worth reference. The contents are as follows
Starting with version 5.2, PHP native provides Json_
Before I wrote a simple example of PHP return JSON data, just online, suddenly found an article, also introduced JSON, very detailed, worth reference. The contents are as followsStarting with version 5.2, PHP native provides the Json_encode () and
One, Json_encode ()
This function is used primarily to convert arrays and objects into JSON format. Let's look at an example of an array conversion:
$arr = Array (' A ' =>1, ' B ' =>2, ' C ' =>3, ' d ' =>4, ' e ' =>5);
Echo Json_encode
Before I wrote a simple example of PHP return JSON data, just online, suddenly found an article, also introduced JSON, very detailed, worth reference. The contents are as followsStarting with version 5.2, PHP native provides the Json_encode () and
Starting with version 5.2, PHP native provides Json_encode () and Json_decode () functions, which are used for encoding and decoding.
one, Json_encode ()This function is used primarily to convert arrays and objects into JSON format. Let's look at
Starting with version 5.2, PHP native provides Json_encode () and Json_decode () functions, which are used for encoding and decoding.
1, Json_encode ()This function is used primarily to convert arrays and objects into JSON format. Let's look at an
Create a table with SQL first and insert data into the tableCREATE TABLE ContactInfo (UID Mediumint (8)Unsigned not NULL auto_increment, #联系人IDName varchar (not NULL), #姓名Deparmentid char (3) not NULL, #部门编号Address varchar (not NULL), #联系地址Phone
PhpArray Sorting
The elements in the array can be sorted in descending or ascending order, in alphabetical or numerical terms.
PHP-Array sorting functionIn this chapter, we will introduce the following PHP array sorting functions:
First, regular expression1. "/" stands for delimiters, "^" stands for the starting symbol, "$" for the end symbol$str 1= "Abc123def45ghjk6789lou";$str 2= "ABCDE5FG2H6JKL";$reg = "/\d/"; Match a number2. Echo preg_replace ($reg, "#", $str 1); Replace
I. Classification of PHP arraysThe arrays in PHP are divided into associative arrays and indexed arrays, depending on the subscript:Indexed array: The subscript starts at 0 and grows sequentially.$arr =[1,2,3,4,5];Associative arrays: The subscript
Before I wrote a lot of PHP web development in the application of XML for data interaction, the two days through the PHP parsing JSON and interactive examples to learn and understand the application of JSON in PHP, feel very convenient, in PHP
Returns a single piece of data as a one-dimensional indexed array: mysql_fetch_rowCall format: $row = mysql_fetch_row ($query)Function: Returns a single piece of data in the result setParameter: mysql_query The resource identifier returnedReturn
The array function in PHP allows you to access and manipulate arrays. Supports simple arrays and multidimensional arrays. The PHP Array function is part of the PHP core. These functions can be used without installation.
Definition and usage
The
1. Establishing a database connection
Copy CodeThe code is as follows:
$mysqli = new Mysqli ("localhost", "root", "" "," mydb ");
?>
Establishing a database connection requires four parameters, namely the database address, the database access
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.