Check out my twitter script by CMXads
PHP Gallery PHP Gallery is a free php image script. | Sell your soul Believeth in me an hath everlasting life | Sharp Stuff Switchblades Icepicks and german knives | Viking gear Gear Gifts and Apparel |
here are some of the best and useful php scripts and snippets to help in your projects. Php displayed below. Use the search for specific script lookups. Click the category links to view scripts in Javascript and cgi. To add your own script click the link and add your useful script example.
Convert an array into object values and objects into arrays
convert array objects
arrays-and-objects date added Jan 2013
<?php
function array2object($array) {
if (is_array($array)) {
$obj = new StdClass();
foreach ($array as $key =
> $val){
$obj->$key = $val;
}
}
else {
$obj = $array; }
return $obj;
}
function object2array($o
bject) {
if (is_object($object)) {
foreach ($object as $
key => $value) {
$array[$key] = $value;
}
}
else {
$array = $object;
}
return $array;
}
// example:
$array = array('foo' => 'bar', 'one' => 'two',
'three' => 'four');
$obj = array2object($array);
print $obj->o
ne; // output's "two"
$arr = object2array($obj);
print $arr['f
oo']; // output's bar
?>