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

Are there holes in the code below. Is it safe to use. I will no longer use an array

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

+3
source share
4 answers

php is dynamically typed. there is nothing wrong with choosing brevity due to clarity. you may want the data types of your variables to remain consistent throughout the function / method / class / subroutine. but nothing in this language prevents you otherwise.

+2
source

Not really, but using a different variable name for the array can improve readability, as this is not a message yet.

+4

, . $records_msg - , .

, , $records_messages, String - $records_message.

+4

Another thing. If you have an array in an array, you will 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
+2
source

Source: https://habr.com/ru/post/1757326/


All Articles