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


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

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


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.


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.


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);  ?>  


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »