SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Php Notice ??

  1. #1
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php Notice ??

    Hi,

    Recently I came across I came across with crazy requirement regarding PHP NOTICE.

    Consider array
    $range=array('today'=>10001,'threeday'=>10002);
    Now,

    $qty=$range['today']+$range['threeday'];

    Notice: Undefined index: today
    PHP Notice: Undefined index: threeday

    So i added

    isset() for today and threeday but notice are something which are popping up again and again.

    how am i suppose to see these array index?? in this example i have only to so i can use check for isset what if i have a dynamic array?

    the real problem is I have to solve them and error_reporting cann't be set to E_ALL^E_NOTICE ... I can't supress them so let me know if there exist some other way to deal with them

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Is that the actual code you're getting errors from? I don't get any, and by var_dump()ing I get
    array(2) { ["today"]=> int(10001) ["threeday"]=> int(10002) }
    int(20003)

  3. #3
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no its not original code ...

    original code array is having 20 array index
    $totalsFields = array('Todays_Count', 'Last_Week', 'Last_Four_Week');

    I have passed this array to funtion

    funtion test($dataArr,$totalFields)
    {
    $arr=array()

    foreach($totalsFields as $t)
    {
    $arr[]=$dataArr[$t] // here this $t thorw undefined index array!!
    }
    }

    Again its just the correct scenario i am in !!! the original code is too long

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    What the error message is saying, is that the $dataArr array doesn't have indexes with the names of the $totalsFields array's values, i.e. 'Todays_Count', 'Last_Week', 'Last_Four_Week'.

    Do you know that it does?

  5. #5
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is fixed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •