Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert an array to string using PHP

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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'];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading