note 60332 added to ref.array
| From: | Atomo64 at osu1 dot php dot net | Date: | Wed, 04 Jan 2006 01:14:58 +0000 |
| Subject: | note 60332 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101173@lists.php.net to get a copy of this message | ||
Here's a simple way to convert an array to a string and vice-versa.
Note that it does NOT support string keys,
for more information take a look at what it does:
<?php
class OptionAsArray
{
function make_the_arr($value)
{
$newValue=array();
$vals=explode('&',$value);
foreach($vals as $v)
{
if($v{0}=='@')
$newValue[]=$this->make_the_arr(
urldecode(substr($v,1)));
else
$newValue[]=urldecode($v);
}
if(empty($newValue))
return false;
else
return $newValue;
}
function make_the_value($arr)
{
$newValue=array();
foreach($arr as $value)
{
if(is_array($value))
$newValue[]='@'.urlencode(
implode('&',$this->make_the_value($value)));
else
$newValue[]=urlencode($value);
}
if(empty($newValue))
return false;
else
return $newValue;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60332
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60332&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60332&report=yes
Search -- http://master.php.net/manage/user-notes.php