Welcome Guest, Not a member yet? Register   Sign In
Foreach data [Solved]
#1

(This post was last modified: 04-30-2018, 01:57 PM by googlemy.)

Hi CI Team,

How to foreach below data?  Confused
PHP Code:
Array ( [sales-by-month] => Array ( [0] =>
Array ( [
month] => Tue Aug 01 00:00:00 +1000 2017 [sales] => [earnings] => 10.00 ) [1] =>
Array ( [
month] => Fri Sep 01 00:00:00 +1000 2017 [sales] => [earnings] => 15 ) [2] =>
Array ( [
month] => Sun Oct 01 00:00:00 +1000 2017 [sales] => [earnings] => 1.88 ) [3] =>
Array ( [
month] => Wed Nov 01 00:00:00 +1100 2017 [sales] => [earnings] => 2.88 ) [4] =>
Array ( [
month] => Fri Dec 01 00:00:00 +1100 2017 [sales] => [earnings] => 8.48 ) [5] =>
Array ( [
month] => Mon Jan 01 00:00:00 +1100 2018 [sales] => [earnings] => 4.73 ) [6] =>
Array ( [
month] => Thu Feb 01 00:00:00 +1100 2018 [sales] => [earnings] => 4.07 ) [7] =>
Array ( [
month] => Thu Mar 01 00:00:00 +1100 2018 [sales] => [earnings] => 13.12 ) [8] =>
Array ( [
month] => Sun Apr 01 00:00:00 +1100 2018 [sales] => [earnings] => 10.74 ) ) ) 

Thanks
Reply
#2

(This post was last modified: 04-30-2018, 07:57 AM by jreklund.)

You can use all PHP functions inside CI.

http://php.net/manual/en/control-structures.foreach.php
PHP Code:
foreach($sales-by-month as $sales) {
echo 
$sales['month'];
echo 
$sales['sales'];
echo 
$sales['earnings'];

Reply




Theme © iAndrew 2016 - Forum software by © MyBB