I use json-decode to transform my data to json table ,
my problem is that i have 2 results json table and i try to normalized to get a single result in standardized format, is there any idea how i normalize my data
resut 1
"PEAR.Commenting.ClassComment.MissingCategoryTag",
"severity": 5,
"type": "ERROR",
"line": 14,
"column": 2,
"fixable": false
},
{
"endPosition": { "character": 63, "line": 69, "position": 1565 },
"failure": "comment must start with a space",
"name": "/home/ke/Front-Analyse/e2e/src/account/register/register.po.ts",
"ruleName": "comment-format",
"ruleSeverity": "ERROR",
"startPosition": { "character": 10, "line": 69, "position": 1512 }
},
{
"endPosition": { "character": 15, "line": 10, "position": 388 },
"failure": "Identifier 'newUser' is never reassigned; use 'const' instead of 'let'.",
"fix": { "innerStart": 377, "innerLength": 3, "innerText": "const" },
"name": "/home/ke/Front-Analyse/e2e/src/account/register/register.e2e-spec.ts",
"ruleName": "prefer-const",
"ruleSeverity": "ERROR",
"startPosition": { "character": 8, "line": 10, "position": 381 }
},
{
"endPosition": { "character": 20, "line": 19, "position": 610 },
"failure": "Identifier 'existantUser' is never reassigned; use 'const' instead of 'let'.",
"fix": { "innerStart": 594, "innerLength": 3, "innerText": "const" },
"name": "/home/ke/Front-Analyse/e2e/src/account/register/register.e2e-spec.ts",
"ruleName": "prefer-const",
"ruleSeverity": "ERROR",
"startPosition": { "character": 8, "line": 19, "position": 598 }
},
result 2
"filePath": "/home/ke/NODEEE/app.js",
"messages": [
{
"ruleId": "no-undef",
"severity": 2,
"message": "'require' is not defined.",
"line": 1,
"column": 19,
"nodeType": "Identifier",
"messageId": "undef",
"endLine": 1,
"endColumn": 26
},
{
"ruleId": "no-undef",
"severity": 2,
"message": "'require' is not defined.",
"line": 2,
"column": 15,
"nodeType": "Identifier",
"messageId": "undef",
"endLine": 2,
"endColumn": 22
},
{
"ruleId": "no-undef",
"severity": 2,
"message": "'require' is not defined.",
"line": 3,
"column": 12,
"nodeType": "Identifier",
"messageId": "undef",
"endLine": 3,
"endColumn": 19
},
Array
(
[totals] => Array
(
[errors] => 2
[warnings] => 0
[fixable] => 0
)
[files] => Array
(
[/home/ke/Test-Code/CODE.php] => Array
(
[errors] => 2
[warnings] => 0
[messages] => Array
(
[0] => Array
(
[message] => Missing file doc comment
[source] => PEAR.Commenting.FileComment.Missing
[severity] => 5
[type] => ERROR
[line] => 2
[column] => 1
[fixable] =>
)
[1] => Array
(
[message] => Expected "for (...) {\n"; found "for (...)\n{\n"
[source] => PEAR.ControlStructures.ControlSignature.Found
[severity] => 5
[type] => ERROR
[line] => 12
[column] => 1
[fixable] =>
)
)
)
)
)
Related
I have following data which I want to merge when it repeats:
{
"employee_id": 7,
"organization_id": 1,
"year": 2021,
"tenure_id": 1,
"leave_name": "Annual Leaves",
"leaves": 26,
"lates": "1",
"leave_id": 1,
"assigned_quota": 99,
"available_quota": "12",
"is_default_leave": 1,
"exceeding": 14
},
{
"employee_id": 15,
"organization_id": 1,
"year": 2021,
"tenure_id": 1,
"leave_name": "test",
"leaves": "25",
"lates": "0",
"leave_id": 16,
"assigned_quota": 50,
"available_quota": "4",
"is_default_leave": 0,
"exceeding": 21
},
{
"employee_id": 15,
"organization_id": 1,
"year": 2021,
"tenure_id": 1,
"leave_name": "Annual Leaves",
"leaves": 25,
"lates": "0",
"leave_id": 1,
"assigned_quota": 99,
"available_quota": "9",
"is_default_leave": 1,
"exceeding": 16
}
know I want it to like this when it merge:
{
"employee_id": 15,
"organization_id": 1,
"year": 2021,
"tenure_id": 1,
"leaves": [
{
"leave_name": "Annual Leaves",
"leaves": 25,
"lates": "0",
"leave_id": 1,
"assigned_quota": 99,
"available_quota": "9",
"is_default_leave": 1,
"exceeding": 16
},
{
"leave_name": "test",
"leaves": "25",
"lates": "0",
"leave_id": 16,
"assigned_quota": 50,
"available_quota": "4",
"is_default_leave": 0,
"exceeding": 21
}
]
}
I have tried using groupby with "employee_id" however it but it gives data with id as parent and and array inside which I dont want anyone here please explain how can I achieve this.
merge method returns merged collection
$c1 = new Collection(['foo']);
$c2 = new Collection(['bar']);
$merged = $c1->merge($c2); // Contains foo and bar.
$c1 = CollectionA::all();
$c2 = CollectionB::all();
$merged = $c1->merge($c2);
Not sure the builting collection methods will do that for you, but some simple PHP code will
$jstring = '[{
"employee_id": 7, "organization_id": 1, "year": 2021,
"tenure_id": 1, "leave_name": "Annual Leaves", "leaves": 26,
"lates": "1", "leave_id": 1, "assigned_quota": 99,
"available_quota": "12", "is_default_leave": 1, "exceeding": 14
},
{
"employee_id": 15, "organization_id": 1, "year": 2021,
"tenure_id": 1, "leave_name": "test", "leaves": "25",
"lates": "0", "leave_id": 16, "assigned_quota": 50,
"available_quota": "4", "is_default_leave": 0, "exceeding": 21
},
{
"employee_id": 15, "organization_id": 1, "year": 2021,
"tenure_id": 1, "leave_name": "Annual Leaves", "leaves": 25,
"lates": "0", "leave_id": 1, "assigned_quota": 99,
"available_quota": "9", "is_default_leave": 1, "exceeding": 16
}]';
$json = json_decode($jstring);
$merged = [];
foreach ($json as $jobj){
if ( array_key_exists($jobj->employee_id, $merged) ) {
// we saw this one before so add to the employee's leaves array
$merged[$jobj->employee_id]->leaves[] = [ "leave_name" => $jobj->leave_name,
"leaves" => $jobj->leaves,
"lates" => $jobj->lates,
"leave_id" => $jobj->leave_id,
"assigned_quota" => $jobj->assigned_quota,
"available_quota" => $jobj->available_quota,
"is_default_leave" => $jobj->is_default_leave,
"exceeding" => $jobj->exceeding
];
} else {
$leaves = [ "leave_name" => $jobj->leave_name,
"leaves" => $jobj->leaves,
"lates" => $jobj->lates,
"leave_id" => $jobj->leave_id,
"assigned_quota" => $jobj->assigned_quota,
"available_quota" => $jobj->available_quota,
"is_default_leave" => $jobj->is_default_leave,
"exceeding" => $jobj->exceeding
];
$obj = new stdClass;
$obj->employee_id = $jobj->employee_id;
$obj->organization_id = $jobj->organization_id;
$obj->year = $jobj->year;
$obj->tenure_id = $jobj->tenure_id;
$obj->leaves[] = $leaves;
$merged[$jobj->employee_id] = $obj;
}
}
print_r($merged);
RESULTS
Array (
[7] => stdClass Object (
[employee_id] => 7
[organization_id] => 1
[year] => 2021
[tenure_id] => 1
[leaves] => Array (
[0] => Array (
[leave_name] => Annual Leaves
[leaves] => 26
[lates] => 1
[leave_id] => 1
[assigned_quota] => 99
[available_quota] => 12
[is_default_leave] => 1
[exceeding] => 14
)
}
)
[15] => stdClass Object (
[employee_id] => 15
[organization_id] => 1
[year] => 2021
[tenure_id] => 1
[leaves] => Array (
[0] => Array {
[leave_name] => test
[leaves] => 25
[lates] => 0
[leave_id] => 16
[assigned_quota] => 50
[available_quota] => 4
[is_default_leave] => 0
[exceeding] => 21
)
[1] => Array (
[leave_name] => Annual Leaves
[leaves] => 25
[lates] => 0
[leave_id] => 1
[assigned_quota] => 99
[available_quota] => 9
[is_default_leave] => 1
[exceeding] => 16
)
)
)
)
I have array and first of all I want to differentiate base on site(key) and site is not limited to 1 or 2
And then sum of opening balance and closing balance of site
like all site(888) total_balance = opening_balance + closing_balance
(999) total_balance = opening_balance + closing_balance
"games": [
{
"id": 240,
"user_id": 1,
"site": "888",
"opening_balance": 5,
"closing_balance": 6
},
{
"id": 243,
"user_id": 1,
"site": "999",
"opening_balance": 3,
"closing_balance": 4
},
{
"id": 244,
"user_id": 1,
"site": "888",
"opening_balance": 5,
"closing_balance": 6
},
And want output like
(site => 888, total_balance => 22 , site => 999, total_balance => 7
(it could b string))
And code I tried:
{
$collection = collect(Site::all())->map(function($item , $key){
return $item["name"];
});
$record = Game::whereIn('site',$collection)->get();
dd($record);
/*$bySite = array();
foreach ($record as $key => $item) {
if(!isset($bySite[$item['site']])) {
$bySite[$item['site']] = array();
}
$bySite[$item['site']][$key] = $item;
}*/
}
after this code which I commented output is
but then I don't know how sum of this
{
"888": {
"0": {
"id": 240,
"user_id": 1,
"site": "888",
"opening_balance": 5,
"closing_balance": 6
},
"2": {
"id": 244,
"user_id": 1,
"site": "888",
"opening_balance": 5,
"closing_balance": 6
},
},
"999": {
"1": {
"id": 243,
"user_id": 1,
"site": "999",
"opening_balance": 3,
"closing_balance": 4,
You can achieve this using Laravel Collection.
$games = [
[
"id" => 240,
"user_id" => 1,
"site" => "888",
"opening_balance" => 5,
"closing_balance" => 6
],
[
"id" => 243,
"user_id" => 1,
"site" => "999",
"opening_balance" => 3,
"closing_balance" => 4
],
[
"id" => 244,
"user_id" => 1,
"site" => "888",
"opening_balance" => 5,
"closing_balance" => 6
]
];
$games = collect($games);
$games = $games->groupBy('site')->map(function($game, $key){
return [
'site' => $key,
'total_balance' => $game->sum('opening_balance') + $game->sum('closing_balance'),
];
})->values();
dd($games->toArray());
And the output would be,
array:2 [▼
0 => array:2 [▼
"site" => 888
"total_balance" => 22
]
1 => array:2 [▼
"site" => 999
"total_balance" => 7
]
]
Code Snippet : https://implode.io/5aPGeH
step
1. foreach ($collection)
2. sum the value and store in array like ($collection->sum('opening_balance'), ($collection->sum('closing_balance')
3. then sum the variable
4. stop loop
5. then $final = $final['site'] . " => " . $final['sum'];
I want to get the products in the order of user input. Suppose if user search
"Z1234","S1234","T2344", then I want products in that particular order. Where Z1234 will be the first record.
How this can be achieved in the elastic search. I have tried using "script" and other ways but it does not work. Below are the example of my script usage.
'_script' => [
'script' => "for(i:scoring) { if(doc[\"custom_44\"].value == i.id) return i.score; } return 0;",
"type" => "number",
'params' => [
'scoring' => [
['id'=>'3MS01',"score" => 1],
['id'=>'29xcs',"score" => 2],
]
],
"order" => "asc"
]
and my working query body is below
Array
(
[size] => 20
[from] => 0
[query] => Array
(
[filtered] => Array
(
[filter] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[bool] => Array
(
[should] => Array
(
[0] => Array
(
[query] => Array
(
[span_near] => Array
(
[clauses] => Array
(
[0] => Array
(
[span_multi] => Array
(
[match] => Array
(
[regexp] => Array
(
[custom_44] => .*3MS01.*
)
)
)
)
)
[slop] => 0
[in_order] => 1
)
)
)
[1] => Array
(
[query] => Array
(
[span_near] => Array
(
[clauses] => Array
(
[0] => Array
(
[span_multi] => Array
(
[match] => Array
(
[regexp] => Array
(
[custom_44] => .*29xcs.*
)
)
)
)
)
[slop] => 0
[in_order] => 1
)
)
)
)
)
)
[1] => Array
(
[term] => Array
(
[deleted] => 0
)
)
[2] => Array
(
[terms] => Array
(
[publication_id] => Array
(
[0] => 35627
)
)
)
[3] => Array
(
[term] => Array
(
[custom_61] => 1
)
)
)
)
)
)
)
[sort] => Array
(
[0] => Array
(
[custom_44] => asc
)
)
)
Is this can be achieved in the elastic search? Do I need to sort after getting the results?
ElasticSearch will sort the results based on the scoring of the specific field in comparison to your input.
For example , if you search for "Z1234 S1234 T2344" it will try to find documents as close as possible to the individual inputs and the analyzer and then it will rank the results accordingly based on the proximity score.
For example , consider the following index :
POST test/doc/
{
"product_name" : "Z1234"
}
POST test/doc/
{
"product_name" : "Z1235"
}
POST test/doc
{
"product_name" : "S1234"
}
POST test/doc
{
"product_name" : "T2344"
}
If you search for "Z1234 S1234 T2344" , it will sort the results based on the score(results closer to your input) and then it will sort the remaining bellow (values such as "Z1235")
GET test/doc/_search
{
"query": {
"match" : {
"product_name" : {
"query" : "Z1234 S1234 T2344",
"operator" : "OR",
"fuzziness": 1
}
}
}
}
"hits": {
"total": 5,
"max_score": 1.2476649,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "AWViqiCOOSSVvlNCAXVu",
"_score": 1.2476649,
"_source": {
"product_name": "Z1234"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "AWViqlZ2OSSVvlNCAXV7",
"_score": 0.6931472,
"_source": {
"product_name": "T2344"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "AWViqj9UOSSVvlNCAXV2",
"_score": 0.51782775,
"_source": {
"product_name": "S1234"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "AWVir1UeOSSVvlNCAXpB",
"_score": 0.23014566,
"_source": {
"product_name": "Z1235"
}
},
{
"_index": "test",
"_type": "doc",
"_id": "AWVirhwlOSSVvlNCAXkQ",
"_score": 0.23014566,
"_source": {
"product_name": "Z1235"
}
}
]
}
}
Now , if you do not want to sort on the scores , but on the field name , the field of the sorting should contain doc values (default by default of Text fields)
GET test/doc/_search
{
"query": {
"match": {
"product_name": {
"query": "Z1234 S1234 T2344",
"operator": "OR",
"fuzziness": 1
}
}
},
"sort": [
{
"product_name.keyword": {
"order": "desc"
}
}
]
}
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "doc",
"_id": "AWVitbfmOSSVvlNCAYA8",
"_score": null,
"_source": {
"product_name": "Z1235"
},
"sort": [
"Z1235"
]
},
{
"_index": "test",
"_type": "doc",
"_id": "AWVita_pOSSVvlNCAYA7",
"_score": null,
"_source": {
"product_name": "Z1234"
},
"sort": [
"Z1234"
]
},
{
"_index": "test",
"_type": "doc",
"_id": "AWVitcPKOSSVvlNCAYBA",
"_score": null,
"_source": {
"product_name": "T2344"
},
"sort": [
"T2344"
]
},
{
"_index": "test",
"_type": "doc",
"_id": "AWVitb1GOSSVvlNCAYA_",
"_score": null,
"_source": {
"product_name": "S1234"
},
"sort": [
"S1234"
]
}
]
}
}
I have been trying to solve my problem for days, but without getting the desidred result. Here's a particular structure for a JSON file:
{
"detections": {
"timestamp": "12/04/2016/ 20:25:00",
"rooms": [
{
"name": "r1",
"sensors": [
{
"id": 10,
"type": "rad",
"value": 100,
"valMax": 600,
"valMin": 100
},
{
"id": 12,
"type": "temp",
"value": 30.5,
"valMax": 1000,
"valMin": 0
}
]
},
{
"name": "r2",
"sensors": [
{
"id": 20,
"type": "temp",
"value": 20.7,
"valMax": 1000,
"valMin": 0
},
{
"id": 15,
"type": "rad",
"value": 800,
"valMax": 600,
"valMin": 100
}
]
}
]
}
}
I must encode with that structure data that I've retrieved from MySQL Database.
It consists of three tables linked with foreign key constraints. Now, the code I've written for this is the following:
while($row = mysqli_fetch_array($result)) {
array_push($detections, array("timestamp"=>$row['timestamp'],
"rooms"=>array("name"=>$row['name'],
"sensors"=>array("id"=>$row['id'], "type"=>$row['type'], "value"=>$row['value'], "valMin"=>$row['valMin'],
"valMax"=>$row['valMax']))
));
}
But it gives me this result:
{
"detections": [{
"timestamp": "2016-09-10 17:59:06",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "1",
"type": "prova2",
"value": "12",
"valMin": "1",
"valMax": "12"
}
}
}, {
"timestamp": "2016-09-11 00:41:21",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "1",
"type": "prova2",
"value": "21",
"valMin": "1",
"valMax": "12"
}
}
}, {
"timestamp": "2016-09-10 19:59:20",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "3",
"type": "prova",
"value": "13",
"valMin": "11",
"valMax": "13"
}
}
}, {
"timestamp": "2016-09-11 00:41:21",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "3",
"type": "prova",
"value": "23.5",
"valMin": "11",
"valMax": "13"
}
}
}]
}
which is similar but not the same :/
As I've noticed from the JSON structure I would get, detections with the same timestamp but with different rooms, sensors and values are collected together... but I don't know how to realize that.
Hope y'all can give me a hand, thanks >.<
You are building your array wrong to achieve that structure.
To achieve the desired structure your array needs to look like this
<?php
array (
'detections' =>
array (
'timestamp' => '12/04/2016/ 20:25:00',
'rooms' =>
array (
0 =>
array (
'name' => 'r1',
'sensors' =>
array (
0 =>
array (
'id' => 10,
'type' => 'rad',
'value' => 100,
'valMax' => 600,
'valMin' => 100,
),
1 =>
array (
'id' => 12,
'type' => 'temp',
'value' => 30.5,
'valMax' => 1000,
'valMin' => 0,
),
),
),
1 =>
array (
'name' => 'r2',
'sensors' =>
array (
0 =>
array (
'id' => 20,
'type' => 'temp',
'value' => 20.699999999999999,
'valMax' => 1000,
'valMin' => 0,
),
1 =>
array (
'id' => 15,
'type' => 'rad',
'value' => 800,
'valMax' => 600,
'valMin' => 100,
),
),
),
),
),
);
Check also check json_decode and json_encode
At the moment im getting a json reponse when i query http://api.steampowered.com/IEconItems_{appid}/GetPlayerItems/v0001/?key={apikey}&steamid={steamid}&format=json
The problem however is that i dont know what to do with this reponse without any aditional info that i cant find anywhere. A part of response im getting when looking at my own cs:go inventory:
{
"id": 235322185,
"original_id": 190991409,
"defindex": 19,
"level": 1,
"quality": 4,
"inventory": 70,
"quantity": 1,
"rarity": 4,
"attributes": [
{
"defindex": 6,
"value": 1130627072,
"float_value": 228
},
{
"defindex": 7,
"value": 1148436480,
"float_value": 975
},
{
"defindex": 8,
"value": 1031063904,
"float_value": 0.059762358665466309
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_smg_p90_mag.mdl"
}
]
},
{
"id": 236527226,
"original_id": 236502674,
"defindex": 27,
"level": 1,
"quality": 9,
"inventory": 82,
"quantity": 1,
"rarity": 3,
"attributes": [
{
"defindex": 6,
"value": 1133608960,
"float_value": 291
},
{
"defindex": 7,
"value": 1142240880,
"float_value": 596.8505859375
},
{
"defindex": 8,
"value": 994750258,
"float_value": 0.0030927178449928761
},
{
"defindex": 80,
"value": 0,
"float_value": 0
},
{
"defindex": 81,
"value": 0,
"float_value": 0
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_shot_mag7_mag.mdl"
}
]
},
{
"id": 236529059,
"original_id": 136971214,
"defindex": 35,
"level": 1,
"quality": 4,
"inventory": 77,
"quantity": 1,
"rarity": 2,
"attributes": [
{
"defindex": 6,
"value": 1077936128,
"float_value": 3
},
{
"defindex": 7,
"value": 1141712676,
"float_value": 564.611572265625
},
{
"defindex": 8,
"value": 1031160533,
"float_value": 0.060122329741716385
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
}
]
}
The id's correnspond with the weapons and the rarity and quantity makes sense too. But i cant be expected to manually find every id of every weapon in every state right? Am i missing a different API that i can use to see what weapon corrensponds with what id?
ps: Sorry for bad english
You will call the GetSchema to determine which items these are. You'll compare DefIndex values against the ones returned by GetSchema
Your work flow will look like this:
Call GetSchema and store result of result['items'] some place to look up later
Call your current call and parse through the items. For each item, look up a result in your stored value from above
GetSchema also has rarities and other values you may need (ie. those attributes)
Compare your inventory defindex (not attributes) value with this schema.
http://api.steampowered.com/IEconItems_730/GetSchema/v0002/?key=xxxxx
For example,defindex = 19 is weapon_p90 on schema.
Try to parse JSON strings into an array. Because this response is not totaly a valid JSON string try to insert this into a new array to parse a valid JSON string.
Such as: {"main_container": [ --> YOUR POSTED CODE <-- ]}
<?php
$jsonResponse = '{"main_container": [
{
"id": 235322185,
"original_id": 190991409,
"defindex": 19,
"level": 1,
"quality": 4,
"inventory": 70,
"quantity": 1,
"rarity": 4,
"attributes": [
{
"defindex": 6,
"value": 1130627072,
"float_value": 228
},
{
"defindex": 7,
"value": 1148436480,
"float_value": 975
},
{
"defindex": 8,
"value": 1031063904,
"float_value": 0.059762358665466309
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_smg_p90_mag.mdl"
}
]
},
{
"id": 236527226,
"original_id": 236502674,
"defindex": 27,
"level": 1,
"quality": 9,
"inventory": 82,
"quantity": 1,
"rarity": 3,
"attributes": [
{
"defindex": 6,
"value": 1133608960,
"float_value": 291
},
{
"defindex": 7,
"value": 1142240880,
"float_value": 596.8505859375
},
{
"defindex": 8,
"value": 994750258,
"float_value": 0.0030927178449928761
},
{
"defindex": 80,
"value": 0,
"float_value": 0
},
{
"defindex": 81,
"value": 0,
"float_value": 0
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
},
{
"defindex": 145,
"value": "models\/weapons\/w_shot_mag7_mag.mdl"
}
]
},
{
"id": 236529059,
"original_id": 136971214,
"defindex": 35,
"level": 1,
"quality": 4,
"inventory": 77,
"quantity": 1,
"rarity": 2,
"attributes": [
{
"defindex": 6,
"value": 1077936128,
"float_value": 3
},
{
"defindex": 7,
"value": 1141712676,
"float_value": 564.611572265625
},
{
"defindex": 8,
"value": 1031160533,
"float_value": 0.060122329741716385
},
{
"defindex": 147,
"value": "models\/weapons\/stattrack.mdl"
}
]
}
]}
';
$jsonDecodeArray = json_decode($jsonResponse, true);
foreach($jsonDecodeArray as $mainContainerItems){
// LOOP THROUGH ALL ITEM GROUP. IN THIS CASE WE HAVE 3 ITEM GROUPS IN
// $mainContainerItems ARRAY
foreach($mainContainerItems as $inventoryItem){
echo $inventoryItem['id']; // will return for example: 236529059
echo $inventoryItem['original_id']; // will return for example: 136971214
echo $inventoryItem['defindex'];
}
}
?>
In this case the resoult will be a multi dimensional array, where you can loop through with multiple foreach.
The resoult is:
$jsonDecodeArray contains the main_container array with all items, where a single item is also an array.
$inventoryItem contains a single item with it's all properties. Like shown below.
Array
(
[id] => 236529059
[original_id] => 136971214
[defindex] => 35
[level] => 1
[quality] => 4
[inventory] => 77
[quantity] => 1
[rarity] => 2
[attributes] => Array
(
[0] => Array
(
[defindex] => 6
[value] => 1077936128
[float_value] => 3
)
[1] => Array
(
[defindex] => 7
[value] => 1141712676
[float_value] => 564.61157226562
)
[2] => Array
(
[defindex] => 8
[value] => 1031160533
[float_value] => 0.060122329741716
)
[3] => Array
(
[defindex] => 147
[value] => models/weapons/stattrack.mdl
)
)
)