CodeIgniter Forums
Array to string conversion - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Array to string conversion (/showthread.php?tid=76982)



Array to string conversion - andreaccident - 07-09-2020

I am trying to print the values from my array:

print_r($google['Google_assigned_previous_day']); -> this works but prints:
Array ( [0] => Array ( [sale] => 0.00 ) ). I want to be able to get the value only. The 0.00

foreach($google['Google_assigned_previous_day'] as $result['Google_assigned_previous_day']) {
  echo $result;
}

I try the code above but I get the error:

Severity: Notice
Message: Array to string conversion§
Filename: views/welcome_message.php
Line Number: 66

Can someone help please?

Thanks


RE: Array to string conversion - jreklund - 07-09-2020

Foreach works this way.

Code:
foreach($google['Google_assigned_previous_day'] as $array) {
  echo $array['sale'];
}



RE: Array to string conversion - andreaccident - 07-09-2020

(07-09-2020, 11:01 AM)jreklund Wrote: Foreach works this way.

Code:
foreach($google['Google_assigned_previous_day'] as $array) {
  echo $array['sale'];
}


Thank you that worked!
I dont remember including "sale" anywhere. Would you mind explaining where that comes from? Thanks!


RE: Array to string conversion - jreklund - 07-09-2020

No idea, you said it where there when you dumped it.

Array ( [0] => Array ( [sale] => 0.00 ) )


RE: Array to string conversion - marcogmonteiro - 07-10-2020

(07-09-2020, 10:53 AM)andreaccident Wrote: Array ( [0] => Array ( [sale] => 0.00 ) ). I want to be able to get the value only. The 0.00


Right here mate.