note 61651 deleted from function.is-array by bjori
| From: | bjori@php.net | Date: | Thu, 30 Mar 2006 13:22:43 +0000 |
| Subject: | note 61651 deleted from function.is-array by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-107027@lists.php.net to get a copy of this message | ||
Note Submitter: cmudyna at gmail dot com
----
You can convert your array into string, to put it into file or database.
<?
function array_to_str ($arr_input, $level=1){
$str_return = "array(\n";
if ( is_array($arr_input) === false ){
return false;
}
foreach ( $arr_input as $key => $value ){
for ( $i=0; $i<$level; $i++ ){
$str_return .= "\t";
}
$str_return .= "[$key] => ";
if ( is_array($value) ){
$str_return .= array_to_str ($value, $level+1);
} else {
$str_return .= "$value\n";
}
}
for ( $i=0; $i<($level-1); $i++ ){
$str_return .= "\t";
}
return $str_return.")\n";
}
// example
$cars= array (
"d"=>"Fiat",
"a"=>"Mercedes",
"b"=>"BMW",
"c"=>"GMC",
"e"=> array (
"d"=>"Daewoo",
"a"=>"Ferrari",
"b"=>"Nissan",
"c"=>"Toyota"
),
"f"=>"Ford"
);
print ("<pre>");
print_r($cars);
print ( array_to_str($cars) );
print("</pre>");
echo "<br>";
?>
output:
Array
(
[d] => Fiat
[a] => Mercedes
[b] => BMW
[c] => GMC
[e] => Array
(
[d] => Daewoo
[a] => Ferrari
[b] => Nissan
[c] => Toyota
)
[f] => Ford
)
array(
[d] => Fiat
[a] => Mercedes
[b] => BMW
[c] => GMC
[e] => array(
[d] => Daewoo
[a] => Ferrari
[b] => Nissan
[c] => Toyota
)
[f] => Ford
)