I am using Codeigniter and its validation rules - a custom callback validation. Anyway, this seems not to be CI related I think.
I've got this function to return a string …
function array_implode($a)
{
return implode(',', $a);
}
… but I always get a message implode(): Invalid arguments passed
But var_dump()
shows me this:
array(2) {
[0]=> string(10) "First item"
[1]=> string(11) "Second item"
}
What is wrong?
Why? Why would you write a function, that calls a std function? Why not write implode(',', $array);
instead of adding the overhead of a function call?
Also: What var_dump
puts out an array? is it a dump of $a
inside the array_implode
function? To be sure $a
is always going to be an array, and you insist on keeping your array_implode
function, edit the code to look like this:
function array_implode(array $a)
{//type hinting: this function will only work if $a is an array
return implode(',',$a);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With