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
精彩评论