Conversion of PHP arrays and objects

巴扎黑
Release: 2023-03-02 16:06:02
Original
1724 people have browsed it

PHP多维数组、对象的转换Array2object and Object2array 
August 4, 2009 – 9:51 pm 

function object2array($object) { 
if (is_object($object) || is_array($object)) { 
foreach ($object as $key => $value) { 
print “$keyrn”; 
$array[$key] = $this->object2array($value); 

}else { 
$array = $object; 

return $array; 


function array2object($arrGiven){ 
//create empty class 
$objResult=new stdClass(); 

foreach ($arrLinklist as $key => $value){ 
//recursive call for multidimensional arrays 
if(is_array($value)) $value=array2object($value); 

$objResult->{$key}=$value; 

return $objResult; 

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!