Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rxnlabs/9c19ec64d08eed38d086 to your computer and use it in GitHub Desktop.
Save rxnlabs/9c19ec64d08eed38d086 to your computer and use it in GitHub Desktop.
PHP - Get the first value from a multidimensional array where the first value may be a serialized array.
<?php
/**
Get first value from multidimensional serialized array
*/
function get_value_from_multidimensional_array( $possible_array ){
if( is_array($possible_array) ){
$maybe_serialized = @unserialize($possible_array[0]);
if( $maybe_serialized !== false ){
$possible_array[0] = $maybe_serialized;
}
$value = $possible_array[0];
$testing = @unserialize($value);
if( $testing !== false ){
$value = $testing;
}
$possible_array = get_value_from_multidimensional_array( $value );
}
return $possible_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment