Skip to content

Instantly share code, notes, and snippets.

@alash3al
Last active April 27, 2017 09:07
Show Gist options
  • Save alash3al/cff99b9002570b1b8126 to your computer and use it in GitHub Desktop.
Save alash3al/cff99b9002570b1b8126 to your computer and use it in GitHub Desktop.
Convert any array to string ( single value )
<?php
/**
* Convert array/nested-array to single value
* @param mixed $arg
* @author Mohammed Al Ashaal
* @license MIT License
* @return string
*/
function array2val($arg)
{
$r = array_values((array) $arg);
$v = null;
for( $i = 0, $c = count($r); $i < $c; ++ $i )
{
if ( is_array($r[$i]) || is_object($r[$i]) )
{
return (string) call_user_func(__FUNCTION__, (array) $r[$i]);
}
else
{
return (string) $r[$i];
}
}
}
// -----------------------------
/**
* Convert array/nseted-array to single value
* @see array2val()
* @param mixed $arg
* @author Mohammed Al Ashaal
* @license MIT License
* @return void
*/
function array2val_byref(&$arg)
{
$arg = array2val($arg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment