Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert Array to object by php

Shulou Source: shulou.com Published: 2022-06-03 05:04:42 09月29日 Update

Editor to share with you how to achieve php array to object, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Php implements the method of converting an array to object: [$array=array ('xxx'= >' xxx'); $vl=json_encode ($array); $ob=json_decode ($vl); print_r ($ob);]

This article operating environment: windows10 system, php 7, thinkpad T480 computer.

Conversion between array and object:

1. Convert the array to Object

$array=array ('a'= > '','b' = > 'bnbbbb',' West' = > 'hee hee'); $vl=json_encode ($array); $ob=json_decode ($vl); echo ""; print_r ($ob)

2. Object transfer array

Add (array) example 1: $data= (array) $Object; var_dump ($data) in front of the Object variable; example 2: / or call this function, turn it into an array, and then take out the corresponding value function object_array ($array) {if (is_object ($array)) {$array = (array) $array } if (is_array ($array)) {foreach ($array as $key= > $value) {$array [$key] = object_array ($value);}} return $array;} these are all the contents of the article "how to convert php to object". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Arrays articles content examples hee hee not so much functions variables most methods more environment computers knowledge systems industry information information channels channels references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Microsoft MariaDB OPPO Reno