Archive for május, 2009
Tomb atirasa „array” formaba
<?php $testarr = array(1, 2, "3", 5); function escape($s) { if (is_string($s)) return "'".$s."'"; else return $s; } function array2php($arr, $deep = 0) { if (!is_array($arr)) return ""; if (array_keys($arr) == array_keys(array_fill(0,count($arr), true))) $keys = false; else $keys = true; $ret = "array("; foreach ($arr as $k => $v) $ret .= ($keys ? escape($k)." => " : "").(is_array($v) ? array2php($v, $deep+1) : escape($v)).", "; $ret = substr($ret, 0, -2); $ret .= ")"; if ($deep == 0) $ret .= ";"; return $ret; } print array2php($testarr); ?>Comments are off for this post