CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2009
    Posts
    160

    [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.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    May 2009
    Posts
    160

    Re: dynamic array

    Quote Originally Posted by PeejAvery View Post
    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;

  4. #4
    Join Date
    May 2009
    Posts
    160

    Re: dynamic array

    Quote Originally Posted by niladhar8@gmail.com View Post
    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.

  5. #5
    Join Date
    May 2009
    Posts
    160

    Re: dynamic array

    Quote Originally Posted by niladhar8@gmail.com View Post
    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

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    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.

  7. #7
    Join Date
    May 2009
    Posts
    160

    Re: dynamic array

    Quote Originally Posted by PeejAvery View Post
    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.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    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
  •  





Click Here to Expand Forum to Full Width

Featured