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'];
}