note 73900 added to ref.array
| From: | alishahnovin at hotmail dot com | Date: | Wed, 14 Mar 2007 20:54:51 +0000 |
| Subject: | note 73900 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124456@lists.php.net to get a copy of this message | ||
If you need an array to implode to strings, but need the quotes:
I had a string like this:
<?php $s = "1,2,3,4,5"; ?>
No control over this. That's what the string looks like.
And needed this to be outputted like so:
"1","2","3","4","5"
Here's what I did:
<?php
$s = "1,2,3,4,5";
echo string_to_strings($s);
function string_to_strings($s) {
return substr(array_to_string(array_reverse(explode(",", $s))),0,-1);
}
function array_to_string($a) {
if (sizeof($a)!=0) {
$r = '"' . array_pop($a) . '",' . array_to_string($a);
return $r;
}
}
?>
Anyone know of any other methods?
----
Server IP: 66.207.199.35
Probable Submitter: 204.244.149.125
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/73900
Del: integrated -- https://master.php.net/note/delete/73900/integrated
Del: useless -- https://master.php.net/note/delete/73900/useless
Del: bad code -- https://master.php.net/note/delete/73900/bad+code
Del: spam -- https://master.php.net/note/delete/73900/spam
Del: non-english -- https://master.php.net/note/delete/73900/non-english
Del: in docs -- https://master.php.net/note/delete/73900/in+docs
Del: other reasons-- https://master.php.net/note/delete/73900
Reject -- https://master.php.net/note/reject/73900
Search -- https://master.php.net/manage/user-notes.php