tags:

views:

59

answers:

4

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

+4  A: 

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

Vinicius Pinto
+4  A: 

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.

Znarkus
+1  A: 

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
netme
thanks but mine will never have a array inside a array
Web Developer
@user406659: "never" is a long time. I've seen (and sometimes written) a lot of code which originaly assumed "that'll never happen".
Piskvor
+1  A: 

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.

stillstanding
thanks but i wont be using it else where
Web Developer