-2

I have this array :

array(2) {
    ["ok"]=> bool(true)
    ["result"]=> array(3) {
        ["id"]=> int(115133849)
        ["first_name"]=> string(5) "drugs"
        ["username"]=> string(7) "darubot"
    }
}

I wanna echo only '115133849'. How i can? I try loop but don't work.

Serlite
  • 12,130
  • 5
  • 38
  • 49

3 Answers3

2

Try with:

$yourArray["result"]["id"];
Mindastic
  • 4,023
  • 3
  • 19
  • 20
0

Put that array into a variable for example $arrayVar now print like this:

echo $arrayVar["result"]["id"]
Imran
  • 4,582
  • 2
  • 18
  • 37
0

assuming array name is $array with many elements

<?php
     $array = array( "ok" => "true",
                     "result" => array("id" => 115133849,
                                       "first_name" => "drugs",
                                       "username" => "darubot"
                                       )  
     );

     echo $array["result"]["id"];
Salah
  • 139
  • 6