Home > Backend Development > PHP Tutorial > json or serialize

json or serialize

WBOY
Release: 2016-06-06 20:28:35
Original
1307 people have browsed it

Preferred method to store PHP arrays (json_encode vs serialize)
大都推荐json_encode,大家实际中用哪个?

回复内容:

Preferred method to store PHP arrays (json_encode vs serialize)
大都推荐json_encode,大家实际中用哪个?

<code><?php $arr   = array("one", "two", "three", "four", "four", "four", "four");
    $start = microtime(true);
    for($i = 1; $i<1000000; $i++){
        $string = json_encode($arr);
    }
    $end   = microtime(true);
    echo $end - $start;
    
    echo "<hr>";
    
    $arr   = array("one", "two", "three", "four", "four", "four", "four");
    $start = microtime(true);
    for($i = 1; $i</code>
Copy after login

分析了一下时间,json_encode 比serialize 更胜一筹。如果从跨语言角度+数据库说。存JSON的话,其他语言如果有访问数据库的需要,那么json_encode 就是必备了。

通常无论是json_encode还是serialize都不会成为性能瓶颈,所以抛开性能,而考虑可读性、可扩展而言,json_encode最终的胜出:

json_encode serialize
可读性 基本不可读
可扩展 高,其他语言都能解析 只能PHP自己玩
Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template