Jump to content

Search the Community

Showing results for tags 'foreach arrays'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I'm still pretty new to php and have an issue i'm trying to solve, I have the following two arrays The first one is contains product id's and the quantity ordered Array ( [35659] => 1 [35699] => 1 [35735] => 2 ) The second one contains warehouse locations that stock the product and the quantity they have available Array ( [35659] => Array ( [9] => 10 [114] => 1 [126] => 0 ) [35699] => Array ( [9] => 8 [114] => 0 [126] => 5 ) [35735] => Array ( [9] => 10 [114] => 0 [126] => 0 ) ) So what I am trying to do is loop through and add to an array each warehouse that meets the quantity of the order here is my code: $stockrequired = array('35659' => '1', '35699' => '1', '35735' => '2'); $instock = array(); foreach ($locations as $location) { foreach($stockrequired as $id => $qty){ if($stockavailable[$id][$location] >= $qty){ $instock[$id] = $location; } } } print_r($instock); However this produces the following which is the last warehouse that meets the quantity. Array ( [35659] => 114 [35699] => 126 [35735] => 9 ) What I need is all the warehouses the meet the quantity for each product e.g. my desired outcome will be below. I'm guessing my loop is getting reset or something? Any help would be appreciated. Array ( [35659] => 9 [35659] => 114 [35659] => 9 [35699] => 126 [35735] => 9 )
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.