View Full Version : How do I turn an array into a string?
davidtymon
02-11-2009, 11:50 AM
hi all,
Can you please tell me how do I turn an array into a string?
Thanks
sysout
02-11-2009, 12:04 PM
PHP not like C/C++
String in PHP doesn't consist of array of char like C
Using implode (http://www.php.net/implode)().
sysout
02-11-2009, 12:25 PM
This is the example :
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
?>
Yeah, good idea.
Btw, what is the diffrence between explode and strtok?
Thanks
Quite a lot.
$str = "foo\nbar\tbaz\n\tquux";
explode("\n\t", $str); // array("foo\nbar\tbaz", 'quux');
strtok($str, "\n\t"); // 'foo'
strtok("\n\t"); // 'bar'
strtok("\n\t"); // 'baz'
strtok("\n\t"); // 'quux'
strtok("\n\t"); // false
sysout
02-12-2009, 11:36 PM
nice...
thanks, I've learnt from you
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.