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?
CodePudding user response:
you are getting value in another array like this
$arr = array(array('count' => 44.35));
to get the inner value you have to access it like this:
print_r($profits['totalProfit'][0]['count']);
$totalProfitsArray = $profits['totalProfit'][0]['count'];