How to properly display the array?

Good evening, there is an array of
Array
(
 [detail] => Array
(
 [0] => Array
(
 [analog] => Price
 [caption] => Engine oil HELIX ULTRA 5W-40 4L
 [code] => 550040755
 [currency] => RUB
 [dataprice] => 2018-05-17 15:27:29
 [delivery] => 4
 [deliverydays] => 0
 [deliveryDisplay] => 0-4
 [id] => 0_0
 [price] => 1995.42
 [userformat_price] => 1996
 [producer] => SHELL
 [rest] => 2654
 [minOrderCount] => 1
 [stock] => Cella995/1
 [RegionName] => Moscow
 [bra_id] => 10340
 [cella_id] => 31448
 [PercentRefuse] => 4
 [n_file] => 1
 [supplier_comment] => Return impossible
Official distributor Shell.
 [arrival_date] => Array
(
)

 [b_id] => 62C368C651BBE3F125BF80237C9F62176D639556BA42CB82F834FCF8FA81FB0FACD81B6AF329141E8C6058F05F142BFA33DB52797F0161E992290C1DEC2C414D41860A26323A36BFDCD3482DB6A94F0C281CAA328FBCB6E8A92FEEE6C02A4BF0F4A76DF978E1F42050214CA0655E687B5D42BF962121552CBFC4071C21457256F3863303E5894D5AB89F794EF9FE276CC3E94EFC03B181BD0FBBE942901D1A52
)

 [1] => Array
(
 [analog] => Price
 [caption] => Shell Helix Ultra 5w-40 4l
 [code] => 550040755
 [currency] => RUB
 [dataprice] => 2018-05-16 01:27:07
 [delivery] => 2
 [deliverydays] => 1
 [deliveryDisplay] => 1-2
 [id] => 0_1
 [price] => 2019.71
 [userformat_price] => 2020
 [producer] => SHELL
 [rest] => 2000
 [minOrderCount] => 1
 [stock] => Cella1157/1
 [RegionName] => Moscow
 [bra_id] => 10340
 [cella_id] => 45551
 [PercentRefuse] => 6
 [n_file] => 1
 [supplier_comment] => Return with deduction of 30%
ACTION. When buying goods Willson ws01241, ws01238, ws01239, ws01240, ws01236, ws01237, ws01276, ws01275 a gift is a one item brand Problesk: Pb3001, Pb3002, Pb7001, Pb4001.
 [arrival_date] => 2018-05-21 15:30:00
 [b_id] => 62C368C651BBE3F125BF80237C9F62176D639556BA42CB82F834FCF8FA81FB0F28528AD7A2DEF5D0ED3B6A3B533C06BC3154D3E43BF274508AD2B69252CE5F924E7A4D11EB4FD30B84A8C833FB3671A9520F8F43CAEBAD098CC020F6A49D01D510D8EBD66C8F978ADDE3BB79FF0BFB61D3638C61C2E46030BFCA6B59409CE83F7A26B8882810613DE6C64506C129A33C
)

 [2] => Array
(
 [analog] => Price
 [caption] => Shell Helix Ultra 5w40 engine oil 4L/4
 [code] => 550040755
 [currency] => RUB
 [dataprice] => 2018-05-17 10:36:15
 [delivery] => 3
 [deliverydays] => 1
 [deliveryDisplay] => 0-1
 [id] => 0_2
 [price] => 2058.45
 [userformat_price] => 2059
 [producer] => SHELL
 [rest] => 1534
 [minOrderCount] => 1
 [stock] => Cella1130/1
 [RegionName] => Moscow
 [bra_id] => 10340
 [cella_id] => 42119
 [PercentRefuse] => 6
 [n_file] => 1
 [supplier_comment] => Official distributor/dealer of products under the brands of Chevron, LAVR, WD-40, POXIPOL, ALTECO, Turtle Wax, Petro-Canada, PEAK, LIQUI MOLY, KIXX, DYNAMATRIX, ODIS, MANNOL, SCT.
 [arrival_date] => 2018-05-18 18:00:00
 [b_id] => 62C368C651BBE3F125BF80237C9F62176D639556BA42CB82F834FCF8FA81FB0FA404F388FCAF01DE395ABB6E5913E556053B4234B2F1BA37D871D0F5EB26E1A24543228AF9D1257EAE40E02951ED3C38FD820EDB6AE2EC54714D25B88ACA9DF148508E6CE7DF015F17E1A4A1BEB9DB7D5C88259B9BAD4E36685141C296CA2C8609190E9579A24C08F7C6B072C4F9FC49B7B206617B77DA4AFC5E228D5AA8095F
)





)

)

Deduce
foreach ($xml_result_adeo['detail'] as $detail) {
print $detail['caption']; //prints all the names on the list
}

All good, got what I needed, but this array
Array
(
 [detail] => Array
(
 [analog] => Price
 [caption] => motomarina the MICHELIN 180
 [code] => 990721
 [currency] => RUB
 [dataprice] => 2018-05-17 18:27:05
 [delivery] => 2
 [deliverydays] => 1
 [deliveryDisplay] => 0-2
 [id] => 0_0
 [price] => 14257.41
 [userformat_price] => 14258
 [producer] => MICHELIN
 [rest] => 1
 [minOrderCount] => 1
 [stock] => Cella778/1
 [RegionName] => Moscow
 [bra_id] => 11044
 [cella_id] => 20351
 [PercentRefuse] => 42
 [n_file] => 1
 [supplier_comment] => Return with deduction of 30%

 [arrival_date] => Array
(
)

 [b_id] => E5EBBA985EB14DB52696E419B4AE8A7228C36441DA30F8E72592FBB032A13CC0730F65F1B11022445D69897557BC08A3CAFCB1683CBE576C44DED72C36874F970EE7D19EA4D52E492F489309F4E14658F43925A8F8E6BA329589A1D2E6BF9221621F4B11288133AB4D5787CB729A8F89672D36F2535F8ABB21799FCB1C2C501E6664D10D73FD8C7587CA13A7E440F003168470EB33116FF02D986E60AE6C881C
)

)

Deduce
foreach ($xml_result_adeo['detail'] as $detail) {
print $detail['caption']; //

}

outputs something like ��9�2210011M how to bring it all about?
June 5th 19 at 21:15
3 answers
June 5th 19 at 21:17
Solution
The second array do not need to touch. It is a regular two-dimensional array.
echo $xml_result_adeo['detail']['caption'];
How can I count the number of attachments in the array?
count($xml_result_adeo['detail']) - not works here and there brings more 1 - Afton29 commented on June 5th 19 at 21:20
In the first array not working? - clovis.Veum49 commented on June 5th 19 at 21:23
I do so
if (count($xml_result_adeo['detail'])>1) {
//here loop
}
else{
//there is no cycle

}


but for some reason he believes is wrong, in all cases, outputs greater than 1
shows 1, a count believes 23
Array
(
 [analog] => Price
 [caption] => Filter
 [code] => R228
 [currency] => RUB
 [dataprice] => 2018-05-17 15:35:04
 [delivery] => 9
 [deliverydays] => 9
 [deliveryDisplay] => 9-9
 [id] => 0_0
 [price] => 833.07
 [userformat_price] => 834
 [producer] => MISFAT
 [rest] => 10
 [minOrderCount] => 1
 [stock] => EU018/3
 [RegionName] => Travel.
 [bra_id] => 11066
 [cella_id] => 50694
 [PercentRefuse] => 10
 [n_file] => 3
 [supplier_comment] => order Cancellation after sending the supplier impossible
A refund is impossible

 [arrival_date] => Array
(
)

 [b_id] => C0C536ABF82E7996AD78F9BDB1304CFFB635CD16B09524247B58198BF43671F2A7B22032FFCB18372A28B070362BCCC6DF0F7190755C649AEA35BD6C6EF2495DC3D2DB6FA8368F430C28313C58D84B8AC2944E904110F179FC4D43A219863929D5B90B0C1D78BC6EDB575C8E40C92C7520A817E2C54F024E7057744E1CD23C2DA865B82B0098CB1A928FBBE158BA61FB
)
23
- Afton29 commented on June 5th 19 at 21:26
In the first example, $xml_result_adeo['detail'] you have a multidimensional array where the keys are [0],[1],[2]... - also arrays. So count($xml_result_adeo['detail']) is greater than 1, but will show significant number of attachments.

In the second example, $xml_result_adeo['detail'], keys [analog],[caption],[code]...
and count($xml_result_adeo['detail']) respectively will be greater than 1.

How can you create arrays?
Show DB query with PHP which executes it. Rather, the problem is there. - clovis.Veum49 commented on June 5th 19 at 21:29
The array comes by api in the form in which I write here, except multidimensional, 27 keys, but why in the second he considers to be 23, although it shows 1, but can not understand - Afton29 commented on June 5th 19 at 21:32
,
although it shows 1, but can not understand

Where shows?
VSM. what you output is a single array, but he believes the 23 key?
Array
(
 [analog] => Price
 [caption] => Filter
....
- clovis.Veum49 commented on June 5th 19 at 21:35
Yes count shows 23 - Afton29 commented on June 5th 19 at 21:38
Well , so because of the keys 23!
count counts all subkeys in the array.

Do this:
if (count($xml_result_adeo['detail'])>1 AND !isset($sml_result_adeo['detail']['id'])) {
//here loop
}
else{
//there is no cycle
}
- clovis.Veum49 commented on June 5th 19 at 21:41
It works , thank you, did not think that we can add the condition. thanks for the help - Afton29 commented on June 5th 19 at 21:44
June 5th 19 at 21:19
whose idea was it to combine the array keys CamelCase, under_score and conventional fused writing o_o
Array get with third-party service api - Afton29 commented on June 5th 19 at 21:22
June 5th 19 at 21:21
text encoding change, use iconv or equivalents.
It is not encoded - Afton29 commented on June 5th 19 at 21:24

Find more questions by tags ArraysPHP