note 105683 added to function.json-encode
| From: | grkworld1 at yahoo dot co dot in | Date: | Wed, 07 Sep 2011 09:45:22 +0000 |
| Subject: | note 105683 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182999@lists.php.net to get a copy of this message | ||
copy the php tagged code in a page
this is use full for multy dimention array
<?php
function arr_2_str($arr,$counter=1,$str="")
{
foreach( $arr as $key=>$value)
{
if(is_array($value))
{
$str.=
$key."=$counter>".arr_2_str($value,($counter+1))."=".$counter.">~Y~|".$counter."|";
}
else
{
$str.=$key."=$counter>".$value."|$counter|";
}
}
return rtrim($str,"|$counter|");
}
function str_2_arr($str,$counter=1,$arr=array(),$temparr=array())
{
$temparr=explode("|$counter|",$str);
foreach( $temparr as $key=>$value)
{
$t1=explode("=$counter>",$value);
$kk=$t1[0];
$vv=$t1[1];
if ($t1[2]=="~Y~")
{
$arr[$kk]=str_2_arr($vv,($counter+1));
}
else
{
$arr[$kk]=$vv;
}
}
return $arr;
}
$arr=array();
$arr[1]="a";
$arr[2][1]="b";
$arr[2][2]="c";
$arr[2][3][1]="d";
$arr[2][3][2][1]="e1";
$arr[2][3][2][2]="e2";
$arr[2][3][3]="f";
print "<pre>";
print_r($arr);
print "<br><br><br>";
print $ssttrr=arr_2_str($arr);
print "<br><br><br>";
print_r(str_2_arr($ssttrr));
/*print "<br><br><br>";
print "use of json";
print "<br><br><br>";
print $sstr=json_encode($arr);
print "<br><br><br>";
print_r(json_decode($sstr));*/
print "</pre>";
?>
----
Server IP: 69.147.83.197
Probable Submitter: 115.249.42.93
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/105683
Del: integrated -- https://master.php.net/note/delete/105683/integrated
Del: useless -- https://master.php.net/note/delete/105683/useless
Del: bad code -- https://master.php.net/note/delete/105683/bad+code
Del: spam -- https://master.php.net/note/delete/105683/spam
Del: non-english -- https://master.php.net/note/delete/105683/non-english
Del: in docs -- https://master.php.net/note/delete/105683/in+docs
Del: other reasons-- https://master.php.net/note/delete/105683
Reject -- https://master.php.net/note/reject/105683
Search -- https://master.php.net/manage/user-notes.php