Last active
April 27, 2017 09:07
-
-
Save alash3al/cff99b9002570b1b8126 to your computer and use it in GitHub Desktop.
Convert any array to string ( single value )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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