国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial PHP慣用庫函數(shù)

PHP慣用庫函數(shù)

Jun 13, 2016 pm 12:27 PM
echo gt json nbsp

PHP常用庫函數(shù)

1.時間和日期

  • 如何獲取時間戳 time()--從1970年開始計算的毫秒數(shù)

echo time();
  • 日期

echo date(<span style="color: #800000;">'</span><span style="color: #800000;">Y-m-d H:i:s</span><span style="color: #800000;">'</span>);
  • 獲取默認是時區(qū)

echo date_default_timezone_get();
  • 默認獲得的時間和本地電腦時間不一致,需要設(shè)置相應(yīng)的時區(qū)

date_default_timezone_set('Asia/Shanghai'); //設(shè)置為上海的時區(qū)echo date(<span style="color: #800000;">'</span><span style="color: #800000;">Y-m-d H:i:s</span><span style="color: #800000;">'</span>);
  • 把時間戳轉(zhuǎn)換成日期呈現(xiàn)出來

echo date(<span style="color: #800000;">'</span><span style="color: #800000;">Y-m-d H:i:s</span><span style="color: #800000;">'</span><span style="color: #000000;">,time());echo </span><span style="color: #800000;">'</span><span style="color: #800000;"><br></span><span style="color: #800000;">'</span><span style="color: #000000;">;echo date(</span><span style="color: #800000;">'</span><span style="color: #800000;">Y-m-d H:i:s</span><span style="color: #800000;">'</span>,time());

?

2.JSON格式數(shù)據(jù)的操作

  • JSON格式的數(shù)據(jù)

?????數(shù)組可以嵌套(數(shù)組中包含數(shù)組)

? ? ?還可以包含對象(內(nèi)部數(shù)據(jù)的值和名字相對應(yīng),鍵值對)

  [1,2,5,7,8,"Hello",[6,7,8],{"h","Hello"}]

  {"h":"Hello","w":"World",[1,2,3]}

  • 數(shù)組生成JSON格式的數(shù)據(jù) encode

<span style="color: #800080;">$arr</span> = <span style="color: #0000ff;">array</span>(1,2,5,8,"Hello","CQUT",<span style="color: #0000ff;">array</span>("h"=>"Hello","name"=>"CQUT"<span style="color: #000000;">));</span><span style="color: #0000ff;">echo</span> 'array format => '.'<br>'<span style="color: #000000;">;</span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$arr</span><span style="color: #000000;">);</span><span style="color: #0000ff;">echo</span> '<br>'<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> 'json formate =>'.'<br>'<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> json_encode(<span style="color: #800080;">$arr</span>);<span style="color: #008000;">//</span><span style="color: #008000;">json_encode將一個對象轉(zhuǎn)成json格式的數(shù)據(jù)</span>

  輸出

  array format =>?
  Array ( [0] => 1 [1] => 2 [2] => 5 [3] => 8 [4] => Hello [5] => CQUT [6] => Array ( [h] => Hello [name] => CQUT ) )?
  json formate =>

  [1,2,5,8,"Hello","CQUT",{"h":"Hello","name":"CQUT"}]

  • 對象生成JSON格式的數(shù)據(jù) encode

<span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">array</span>('h'=>'Hello','w'=>'World',<span style="color: #0000ff;">array</span>(1,2,3<span style="color: #000000;">));</span><span style="color: #0000ff;">echo</span> json_encode(<span style="color: #800080;">$obj</span>);

  輸出

  {"h":"Hello","w":"World","0":[1,2,3]}

  • 將JSON格式的數(shù)據(jù)轉(zhuǎn)換成PHP對象 decode

<span style="color: #800080;">$jsonStr</span> = '{"h":"Hello","w":"World","0":[1,2,3]}'<span style="color: #000000;">;</span><span style="color: #800080;">$obj</span> = json_decode(<span style="color: #800080;">$jsonStr</span><span style="color: #000000;">);</span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$obj</span><span style="color: #000000;">);</span><span style="color: #0000ff;">echo</span> '<br>'<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$obj</span>->h;

  輸出

  stdClass Object ( [h] => Hello [w] => World [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) )?

  Hello

?

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

How to use PHP functions to process JSON data? How to use PHP functions to process JSON data? May 04, 2024 pm 03:21 PM

PHP provides the following functions to process JSON data: Parse JSON data: Use json_decode() to convert a JSON string into a PHP array. Create JSON data: Use json_encode() to convert a PHP array or object into a JSON string. Get specific values ??of JSON data: Use PHP array functions to access specific values, such as key-value pairs or array elements.

What are the most popular golang frameworks on the market? What are the most popular golang frameworks on the market? Jun 01, 2024 pm 08:05 PM

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

&quot;Go Language Development Essentials: 5 Popular Framework Recommendations&quot; As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Quick tips for converting PHP arrays to JSON Quick tips for converting PHP arrays to JSON May 03, 2024 pm 06:33 PM

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

How to optimize iPad battery life with iPadOS 17.4 How to optimize iPad battery life with iPadOS 17.4 Mar 21, 2024 pm 10:31 PM

How to Optimize iPad Battery Life with iPadOS 17.4 Extending battery life is key to the mobile device experience, and the iPad is a good example. If you feel like your iPad's battery is draining too quickly, don't worry, there are a number of tricks and tweaks in iPadOS 17.4 that can significantly extend the run time of your device. The goal of this in-depth guide is not just to provide information, but to change the way you use your iPad, enhance your overall battery management, and ensure you can rely on your device for longer without having to charge it. By adopting the practices outlined here, you take a step toward more efficient and mindful use of technology that is tailored to your individual needs and usage patterns. Identify major energy consumers

See all articles