note 61651 added to function.is-array

From: Date: Wed, 08 Feb 2006 13:02:03 +0000
Subject: note 61651 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-103308@lists.php.net to get a copy of this message
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 ) ---- Server IP: 81.223.254.85 Probable Submitter: 83.20.116.188 ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61651 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61651&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61651&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103308) next »