简体   繁体   中英

how i can get data query cake php in array var_dump?

i have a query in cake php

$sql ="select menu from ms_menu";
$result=advancedQuery($sql); 
foreach ($result as $data ){
    echo $data[0];
}

the case is : the $data[0] show nothing ...

i try to

var_dump $result;

and the result is

output

array(1) { [0]=> array(1) { [0]=> array(1) { ["NAMA_MENU"]=> string(6)  "Report" } } }

i need to get "Report" to my variabel..

anyone knows the problem ?? please help

First of all, var_dump(); is a function and you should use it like this : var_dump($result);

Here is your information hierarchy :

- $data
-- $data[0]
--- $data[0][0]
---- $data[0][0]['NAMA_MENU']

Here, you are trying to echo an array ( $data[0] ). It's not possible.

You can :

— Create a double recursive foreach :

foreach ($result as $data ){
    foreach ($data[0] as $innerData ){
        echo $innerData['NAMA_MENU'];
    }  
}

— Get directly your needed value inside the first foreach :

foreach ($result as $data ){
    echo $data[0][0]['NAMA_MENU'];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM