Still new in PHP and I am trying to convert an array to string in my code below:
$totalProfitsArray = print_r($profits['totalProfit']); If I echo the $totalProfitsArray variable above i get this result:
Array ( [0] => Array ( [count] => 44.35 ) ) which is fine but i want to echo only the 44.35 value. So i tried to use the implode method like this:
implode("", $totalProfitsArray); but still didn't work and i get this error:
implode(): Invalid arguments passed
What I am doing wrong? Is there any other easy way to convert the array in string and print the result?
var_exportyour original$profitsarray, it makes it easier for others to understand your data structure and consume/work with the data.print_rwill likely betrue, so your assignment above to an array is misguided.serialize()andunserialize()functions. .... php.net/manual/en/function.serialize.phpprint_r()always returns true unless the 2nd parameter is specified astrue, in whichprint_r()will return a string of it's results as opposed to echoing the contents. .... php.net/manual/en/function.print-r.php