We have the following array

array(1) { ["таблица 1"]=> array(3) { [1]=> array(4) { [0]=> string(31) "Название таблицы" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" } [2]=> array(4) { [0]=> string(16) "колонка 1" [1]=> string(16) "колонка 2" [2]=> string(16) "колонка 3" [3]=> string(16) "колонка 4" } [3]=> array(4) { [0]=> string(5) "д1.1" [1]=> string(5) "д2.1" [2]=> string(5) "д3.1" [3]=> string(5) "д4.1" } } } 

How to get the name of the object, "table 1"? and if there are several, how to get everything?

I apologize for such a simple question, I simply cannot form a request in Google so that I would find the answer, thanks!

    1 answer 1

    array_keys may be suitable array_keys

    https://secure.php.net/manual/ru/function.array-keys.php

     $keys = array_keys($arr); //$arr - ваш массив 

    $keys will be an array whose values ​​are keys from the $arr array.

    In dogonku example from official documentation

     $array = array(0 => 100, "color" => "red"); print_r(array_keys($array)); 

    Displays:

     Array ( [0] => 0 [1] => color ) 
    • Enter key points in the response body, the link to stackoverflow is not the answer. - Naumov
    • I would be extremely grateful for an example, and how to continue working with keys, as I understood something like this: $ key = array_keys ($ array); echo $ array [$ key [0]] [1] [0]; So we have to get the name of the table from my example array, right? - Vladimir Alexandrov
    • Yes, I understood correctly, everything works, but for some reason: echo $ array [$ key [0]] [1] [0]; gives the result "Table nameNULL", who will tell you why? - Vladimir Alexandrov
    • @Vladimir Aleksandrov, and except for the specified code, nothing else is done? NULL could be output by another echo operator in the code later. - DanielOlivo
    • @DanielOlivo, you are absolutely right! overlooked, thanks! - Vladimir Alexandrov