There was a need to search for and display information on a condition (in this situation, the value is 15185211, but as can be seen in the code from the example, it is in different keys. Float_value is the first array and value is the second array.) From ['attributes']. There was a hitch in the appeal to ['attributes'] as it is in arrays that php itself numbers after decoding from the JSON format. My example from the example received a sequential number 65 (and further there are the same arrays with consecutive numbers 0,2,3,4 ... 66, 67, 68 ... 333, etc.) There are many such arrays and their number changes . And I can not figure out how to specify such arrays automatically and not manually drive in each number of the array, although this is unrealistic since the number is different each time. For example, $ items_array = $ backpack_data ['result'] ['items'] [ how to specify all numbered arrays, if their number is not known ] ['attributes'];
Now I use this code to fetch data from arrays by their ['defindex']. We are looking for a match ['defindex'] from the first array in the second one and, if successful, output additional information (image, description, level, etc.) that is taken from the second array and matches the one matched with the first value ['defindex'].
$items_array = $backpack_data['result']['items']; // ΠΠ΅ΡΠ²ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² $schema_array = $schema_data['result']['items']; // ΠΡΠΎΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ² foreach($items_array as $item)// ΠΠ΅ΡΠ²ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² { foreach($schema_array as $schema_item)// ΠΡΠΎΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ² if($schema_item['defindex'] == $item['defindex']) { echo '<img src="'.$schema_item['image_url'].'" title="'.$schema_item['item_name'].' '.$item['level'].' level">'; break; } } It is also not difficult to display information, for example on ['level']. Adding the condition if ($ item ['level'] == 100)
$items_array = $backpack_data['result']['items']; // ΠΠ΅ΡΠ²ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² $schema_array = $schema_data['result']['items']; // ΠΡΠΎΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ² foreach($items_array as $item)// ΠΠ΅ΡΠ²ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² { foreach($schema_array as $schema_item)// ΠΡΠΎΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ² if ($item['level'] == 100){ if($schema_item['defindex'] == $item['defindex']) { echo '<img src="'.$schema_item['image_url'].'" title="'.$schema_item['item_name'].' '.$item['level'].' level">'; break; } } } Here we find the data corresponding to the condition, take them ['defindex'] and then as above we are looking for a match, we print the information to the page.
And I cannot figure out how to specify such arrays automatically, and not manually enter each number of the array, although this is unrealistic since the number is different each time, and then how can I get ['defindex'] appropriate for the first array from ['attributes']? and compare with the second array by ['defindex'].
Sorry, I did not post the source data which I parse after decoding from the JSON format:
The first PHP array:
Array ( [result] => Array ( [items] => Array ( [65] => Array ( [id] => 2008542462 [original_id] => 1057898213 [defindex] => 617 [level] => 10 [quality] => 6 [inventory] => 2147483947 [quantity] => 1 [origin] => 0 [style] => 1 [attributes] => Array ( [0] => Array ( [defindex] => 142 [value] => 1265087803 [float_value] => 15185211 ) [1] => Array ( [defindex] => 261 [value] => 1265087803 [float_value] => 15185211 ) [2] => Array ( [defindex] => 292 [value] => 1115684864 [float_value] => 64 ) [3] => Array ( [defindex] => 388 [value] => 1115684864 [float_value] => 64 ) ) ) ) ) ) The second array (for more understanding)
[1196] => Array ( [name] => Paint Can 11 [defindex] => 5037 [item_class] => tool [item_type_name] => ΠΠ½ΡΡΡΡΠΌΠ΅Π½Ρ [item_name] => ΠΠΎΠ»ΠΎΡΠΎΠΉ [item_description] => ΠΡΠΈΠΌΠ΅Π½ΡΠ΅ΡΡΡ Π΄Π»Ρ ΠΎΠΊΡΠ°ΡΠΈΠ²Π°Π½ΠΈΡ ΠΏΡΠ΅Π΄ΠΌΠ΅ΡΠΎΠ². [proper_name] => [model_player] => [item_quality] => 6 [image_inventory] => backpack/player/items/crafting/paintcan [min_ilevel] => 5 [max_ilevel] => 5 [image_url] => /icons/paintcan.9046edf23b64960a4084dad29d05d2c902feec78.png [image_url_large] => /icons/paintcan_large.b8e71a4720fa96d963f45db61c013185ca637aa6.png [craft_class] => tool [craft_material_type] => tool [capabilities] => Array ( [can_craft_mark] => 1 [can_be_restored] => 1 [strange_parts] => 1 [can_card_upgrade] => 1 [can_strangify] => 1 [can_killstreakify] => 1 [can_consume] => 1 ) [tool] => Array ( [type] => paint_can [usage_capabilities] => Array ( [paintable] => 1 ) ) [used_by_classes] => Array ( ) [attributes] => Array ( [0] => Array ( [name] => set item tint RGB [class] => set_item_tint_rgb [value] => 15185211 ) ) )