www.webdeveloper.com
Results 1 to 3 of 3

Thread: Warning: Invalid argument supplied for foreach() - Please Help

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    Warning: Invalid argument supplied for foreach() - Please Help

    Hello,

    Iīm having an issue in the follow code, displaying the warning "Warning: Invalid argument supplied for foreach()", can i donīt know what is happening, anyone can help me?

    The code:

    PHP Code:
    foreach ( $prices as $name => $product_price  ){
                if(
    $name != 'costPrice'){
                    
    $priceFormated[$name] = $currency->createPriceDiv($name,'',$prices,true);
                }
            } 
    Any help will be appreciated.

    Thank you very much

    Zig

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    Presumably $prices is not an array at that point (or an object that supports iteration), so you need to verify what's happening wherever it gets set, and possibly put in some defensive code to handle situations where it does not get set as an array.
    Last edited by NogDog; 04-05-2013 at 12:29 PM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2013
    Posts
    2
    Yes, thatīs what a thought, then i set the code like this, and the warning is gonne:

    PHP Code:
    if (is_array($prices)) {
            foreach ( 
    $prices as $name => $product_price  ){
                if(
    $name != 'costPrice'){
                    
    $priceFormated[$name] = $currency->createPriceDiv($name,'',$prices,true);
                }
            }

    Thanks for your help NogDog

    Regards,

    Zig

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles