stdobj to array php
The lazy one-liner method
You can do this in a one liner using the JSON methods if you're willing to lose a tiny bit of performance (though some have reported it being faster than iterating through the objects recursively - most likely because PHP is slow at calling functions). "But I already did this" you say. Not exactly - you used json_decode on the array, but you need to encode it with json_encode first.
Requirements
The json_encode and json_decode methods. These are automatically bundled in PHP 5.2.0 and up. If you use any older version there's also a PECL library (that said, in that case you should really update your PHP installation. Support for 5.1 stopped in 2006.)
Converting an array/stdClass -> stdClass
$stdClass = json_decode(json_encode($booking));
Converting an array/stdClass -> array
The manual specifies this second parameter of json_decode as:
assoc
WhenTRUE, returned objects will be converted into associative arrays.
Hence it will convert the entire thing into an array:
$array = json_decode(json_encode($booking), true);
Source page:http://stackoverflow.com/questions/18576762/php-stdclass-to-array
stdobj to array php的更多相关文章
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- JavaScript Array对象
介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...
- 了解PHP中的Array数组和foreach
1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组 . 2.例子:一般的数组 这里,我 ...
- 关于面试题 Array.indexof() 方法的实现及思考
这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...
- javascript之活灵活现的Array
前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...
- 5.2 Array类型的方法汇总
所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...
- OpenGL ES: Array Texture初体验
[TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...
- Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
随机推荐
- html5 <input> placeholder 属性
带有 placeholder 文本的搜索字段: <form action="demo_form.asp" method="get"> <inp ...
- 318. Maximum Product of Word Lengths ——本质:英文单词中字符是否出现可以用26bit的整数表示
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- YanYan Self Introduction
My Website: http://finehappy.com/
- ubuntu 软件安装的几种方法
说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装.卸载和删除的方法. 一.U ...
- autoLyout纯代码适配
前言 1 MagicNumber -> autoresizingMask -> autolayout 以上是纯手写代码所经历的关于页面布局的三个时期 在iphone1-iphone3gs时 ...
- https://github.com/oneuijs/You-Dont-Need-jQuery
https://github.com/oneuijs/You-Dont-Need-jQuery
- form v
<form name="example_form" action="http://google.com" method="POST"& ...
- sql 行专列 列转行 普通行列转换
转载:http://www.cnblogs.com/newwind521/archive/2010/11/25/1887203.html sql 行专列 列转行 普通行列转换 /* 标题:普通行列转换 ...
- 五大要求让BPM与企业对接
BPM(即业务流程管理)在中国已经有多年的发展历史,但人们经常提到的还是企业对流程的迫切需要,鲜有人讨论什么样的企业才能实施BPM,或者换句话说BPM的本身对企业有什么要求.不是所有的工作都适合BPM ...
- java内部类和外部类
1.使用static可以声明一个内部类, 可以直接在外部调用 class Outer{ // 定义外部类 private static String info = "hello world& ...