-
May 17th, 2011, 12:47 PM
#1
[RESOLVED] dynamic array
i have values stored in an array with key
Code:
$array['total']['2001-11-09'];
the year month and day are as separate variables, how can i print its content out. I tried all below
Code:
$temp = $year."-".$month."-".$day;
echo $array['total'][$temp];
echo $array['total'][."'".$temp."'"];
none work.
-
May 17th, 2011, 01:00 PM
#2
Re: dynamic array
Your first echo is correct. If it's not returning a value...then you have your key incorrect. I'd suggest echoing the $temp as well to make sure.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 17th, 2011, 01:03 PM
#3
Re: dynamic array
Originally Posted by PeejAvery
Your first echo is correct. If it's not returning a value...then you have your key incorrect. I'd suggest echoing the $temp as well to make sure.
yes i did echo my temp, and my source array as well.
the source array has this
$date['total'][2011-01-09] = 60.00;
echo $temp; // 2011-01-09;
-
May 17th, 2011, 01:07 PM
#4
Re: dynamic array
Originally Posted by niladhar8@gmail.com
yes i did echo my temp, and my source array as well.
the source array has this
$date['total'][2011-01-09] = 60.00;
echo $temp; // 2011-01-09;
i think i know what it is.... my array has 2011-01-09 as the key..... in my loop inside the calender where i try and display the amount for that date, it calculates to 2011-01-9 leaving out the 0.
anywork around this.
-
May 17th, 2011, 01:11 PM
#5
Re: dynamic array
Originally Posted by niladhar8@gmail.com
i think i know what it is.... My array has 2011-01-09 as the key..... In my loop inside the calender where i try and display the amount for that date, it calculates to 2011-01-9 leaving out the 0.
Anywork around this.
resolved
-
May 17th, 2011, 01:14 PM
#6
Re: dynamic array
For the sake of others...always share how it was resolved, and mark the thread resolved from in the Thread Tools menu.
I'm assuming you used sprintf().
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 17th, 2011, 01:26 PM
#7
Re: dynamic array
Originally Posted by PeejAvery
For the sake of others...always share how it was resolved, and mark the thread resolved from in the Thread Tools menu.
I'm assuming you used sprintf().
how would i accomplish it using sprintf(); right now i used ternary operator to check if less than 10 and added 0 in front.
sorry bout that, will share it next time, i knew my work around was not clean code..... and did not know resolved was in that menu. will keep that in mind.
-
May 17th, 2011, 01:33 PM
#8
Re: dynamic array
PHP Code:
sprintf("%02d", $year);
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|