$arrayMult = [ ['a','b'] , ['c', 'd'] ];
$arraySingle = call_user_func_array('array_merge', $arrayMult);
// $arraySingle is now = ['a','b', 'c', 'd'];
$person = new stdClass();
$person->firstName = "Taylor";
$person->age = 32;
//Convert Single-Dimention Object to array
$personArray = (array) $person;
//Convert Multi-Dimentional Object to Array
$personArray = objectToArray($person);
function objectToArray ($object) {
if(!is_object($object) && !is_array($object)){
return $object;
}
return array_map('objectToArray', (array) $object);
}
//The array_flatten function will flatten a multi-dimensional array into a single level
$array = ['name' => 'Issac', 'languages' => ['PHP', 'Python']];
$array = array_flatten($array);
// ['Issac', 'PHP', 'Python'];
$singleArray = [];
foreach ($parentArray as $childArray)
{
foreach ($childArray as $value)
{
$singleArray[] = $value;
}
}
function array_flatten($array) {
if (!is_array($array)) {
return FALSE;
}
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = array_merge($result, array_flatten($value));
}
else {
$result[$key] = $value;
}
}
return $result;
}