开发者

PHP : imploding array and storing the result back to same variable

Are there any pit falls in开发者_C百科 the below code . Is it safe to use this way. I will not be using the array again

$records_msg = implode(" ",$records_msg);


Not really, but using a different variable name for the array may improve readability, since it's not a message yet.


That might be confusing to anyone reading your code. First $records_msg is an Array, then further down the code it is a String.

I would probably rename the Array to $records_messages and the String to $records_message.


php is dynamically-typed. there is nothing wrong with choosing brevity at the expense of clarity. you may want the data types of your variables to stay consistent throughout a function/method/class/routine. but nothing in the language prevents you from doing otherwise.


Another thing. If you have array in array, you'll lose it. Example:

<?php
$input = array(1,2,3,array(4,5));
echo implode(',', $input);
?>

returns:

PHP Notice:  Array to string conversion in C:\Temp\1.php on line 3
1,2,3,Array
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜