convert multidimensional array to single array php
$singleArray = [];
foreach ($parentArray as $childArray)
{
foreach ($childArray as $value)
{
$singleArray[] = $value;
}
}
convert multidimensional array to single array php
$singleArray = [];
foreach ($parentArray as $childArray)
{
foreach ($childArray as $value)
{
$singleArray[] = $value;
}
}
php convert object to array multidimensional
// Very fast way (More at pereere.com/php)
$obj = json_decode( json_encode( $obj ), true );
// Recursive Method
// Dont create function if it already exist
if ( ! function_exists( 'convert_object_to_array' ) ) {
/**
* Converts an object to an array recursively.
*
* @param object $obj The object to convert
* @param array $arr Recursive
*
* @return mixed
*
*/
function convert_object_to_array( $obj, &$arr = [] ) {
// Return if @var $obj is not an object (may be an array)
if ( ! is_object( $obj ) && ! is_array( $obj ) ) {
$arr = $obj;
return $arr;
}
foreach ( $obj as $key => $value ) {
if ( ! empty( $value ) ) {
$arr[ $key ] = array();
// Recursively get convert the value to array as well
convert_object_to_array( $value, $arr[ $key ] );
} else {
$arr[ $key ] = $value;
}
}
return $arr;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us