Jump to content

thenorman138

Members
  • Posts

    135
  • Joined

  • Last visited

  • Days Won

    1

thenorman138 last won the day on July 19 2018

thenorman138 had the most liked content!

Recent Profile Visitors

1,634 profile views

thenorman138's Achievements

Advanced Member

Advanced Member (4/5)

1

Reputation

  1. I appreciate the response, and the unique identifier is indeed 'prd'. The issue is that I really need a single array, with stores as sub-array, as this is going straight into a spreadsheet builder and looping through each record (each store being it's own column with either the price or 'none' if no match on store). I was thinking of rather than pushing where I am, just looping on each record in the array and checking to see if 'prd' exists yet: If so, I'll push the store name into the sub-array of $newArray, and if not I'll add the whole record. My issue there is that I was going to use If(array_key_exists) but I don't think that's the right approach here as I need to explicitly state what the 'key' is for the check
  2. Thanks for all the great points there. To answer the biggest question: yes, if a product belongs to 3 stores the data is all the same. Price, prd, id, all of it is exactly the same; it's just a matter of how many stores are 'allowed' to sell the product. So all this eventual spreadsheet will do is give me a list of these products and their assigned prices along with any stores where they could be available. The last example in my question is the closest thing to a real world version of 2 stores having the same product: product and price data is identical, there's just a subarray showing stores
  3. I have code where I'm simply calling an API and I've converted it to loop the call so that I can call it with three different argument values. This is because the API is structured where it can accept one value for that argument at a time, but I need to compare the results of the three calls and I think the best way is to build a single array from the responses by either pushing a value if it exists or pushing the whole index if not. Think of it like the API response can give me data that can be as much as 400 products that are sold across 3 stores. All 400 may be sold in one store, but maybe only 120 in another and 100 in the third. I need my array to be all 400 products but I'll want to have an array within that holds the stores for the given product. Code: $IdentifierTest = 1472; $arguments = ['store 1', 'store 2', 'store 3']; $TestApi = app(TestApi::class); $newArray = array(); foreach($arguments as $argument){ $testResponse = $TestApi->getData($IdentifierTest, $argument); $Data = $testResponse->getResult()->getData(); // get the final results of call //check if array empty, and if so, push all records // if not empty, start checking 'id' against existing array records. If match, push stores. If not, add record to array } $this->makeFile($IdentifierTest, $Data); An example of the response is: array:426 [▼ 0 => prices {#2698 ▼ #container: array:11 [▼ "prd" => 2380 "id" => "173489" "price" => "65.00" ] } The issue is that specific example only shows up when calling the API with 'store 1' and 'store 2' as the argument, but not 'store 3'. What I'd like to do is call the API with each argument and create a new array with a ```stores``` index that pushes the store number if the id exists in the call, like so: array:426 [▼ 0 => prices {#2698 ▼ #container: array:11 [▼ "prd" => 2380 "id" => "173489" "price" => "65.00" stores: array[ 'store 1', 'store 2' ] ] } So when it's called with 'store 1' I would push the response into an array with 'store 1' as the value in 'stores', then on 'store 2' I would take the response and first check to see if the id exists in the array I've made. If it exists, I'll add 'store 2' to the 'stores' and if not I'll make a new index in the array. Basically, if product (id) 178293 is sold in all three stores then that means it would come back in all 3 API response calls and would end up being a single record in this new array with ```stores['store 1', 'store 2', 'store 3']``` How can I create a new array from this where I push only the stores if the id exists in the API call while keeping the current structure?
×
×
  • 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.