-3

It is my array:

 [main] => Array (             
     [data] => Array                 
       ( [777] => Array (... ), 
         [888] => Array (....), 
         [999] => Array (....) ));

I usually use such syntax:

array['main']['data'][0]...

however here I don't know what exactly values are (777, 888, 999).

How could I receive this 777, 888, 999 and also theirs included data?

knva
  • 3
  • 1
  • You cannot do it like the way you have mentioned. Since the key values are dynamic you need to loop through the data with foreach loop and get the values. – Ashok Mar 17 '19 at 16:09

2 Answers2

0

You can use foreach loop and you can access the values in each iteration like below :

<?php 
    foreach($array['main']['data'] as $item) {
        print_r($item['name']); 
       // i assure there is some index as name in the subarray. Change the index value as per your data.
    }
?>

Refer the document ion for further information PHP Foreach loop

Ashok
  • 437
  • 4
  • 9
  • Thank you for your answer. That's exactly what I was looking for. However, how could I know the index name if there is absent in this array, just numbers. – knva Mar 17 '19 at 16:44
  • You just print value of item you will get an idea. If you not sure about the index name just print the entire value and you will get an idea. – Ashok Mar 17 '19 at 16:47
  • But the problem that I don't know this 777 value. I have to request $item['777'] but I don't have this '777' name. It could be any value. – knva Mar 17 '19 at 16:52
  • For each iteration in the loop you don't need that '777' value, because you will single single array while iterating. On the first loop you get details of 777 in the $item and on the second iteration you will get '888' and so on – Ashok Mar 17 '19 at 16:59
  • Thank you very much for your support! It's clear for me now. Wish you good luck in all of your projects! – knva Mar 17 '19 at 17:08
  • Thank you very much, i wish the same for you – Ashok Mar 17 '19 at 17:12
-2

Use foreach loop... Foreach loop. Will solve your problem

  • thank you for your answer, so I will receive each data in it (included array). And how to retrieve this indexes names: '777' for example? – knva Mar 17 '19 at 16:09