开发者

Can't access special key in array in php

when I use following code

foreach($admin_info as $key => $val)
{
echo $key."   ".$val."\n";
}
I will get true result:

id 1
username Moein7tl
password 0937afa17f4dc08f3c0e5dc908158370ce64df86
mail moein7tl@gmail.com
added_time 
super_admin 
last_time 
last_ip 
see_user_per 1
change_user_per 1
see_people_per 1
change_people_per 1
add_people_per 1
remove_people_per 1
see_album_per 1
add_album_per 1
change_album_per 1
remove_album_per 1
see_music_per 1
add_music_per 1
change_music_per 1
remove_music_per 1
admin_per 1
yahoo_per 1
status_per 1
pm_per 1
ip_blocking_per 1

but when I use echo ($admin_info['id']); or with other keys, it will make an error and no result will be shown. where is problem? --edit var_dump($admin_info); will return

object(stdClass)#21 (27) { ["id"]=> string(1) "1" ["username"]=> string(8) "Moein7tl" ["password"]=> string(40) "0937afa17f4dc08f3c0e5dc908158370ce64df86" ["mail"]=> string(18) "moein7tl@gmail.com" ["added_time"]=> NULL ["super_admin"]=> string(0) "" ["last_time"]=> NULL ["la开发者_JAVA百科st_ip"]=> NULL ["see_user_per"]=> string(1) "1" ["change_user_per"]=> string(1) "1" ["see_people_per"]=> string(1) "1" ["change_people_per"]=> string(1) "1" ["add_people_per"]=> string(1) "1" ["remove_people_per"]=> string(1) "1" ["see_album_per"]=> string(1) "1" ["add_album_per"]=> string(1) "1" ["change_album_per"]=> string(1) "1" ["remove_album_per"]=> string(1) "1" ["see_music_per"]=> string(1) "1" ["add_music_per"]=> string(1) "1" ["change_music_per"]=> string(1) "1" ["remove_music_per"]=> string(1) "1" ["admin_per"]=> string(1) "1" ["yahoo_per"]=> string(1) "1" ["status_per"]=> string(1) "1" ["pm_per"]=> string(1) "1" ["ip_blocking_per"]=> string(1) "1" }


I found problem,CodeIgniter will return database result as Object. So I should do it like that $admin_info->id and it solves problem.


Try $admin_info->password, this should work as $admin_info seems to be an object of stdClass.


Your logic is correct, but you may try using echo $admin_info['id']; without the Parenthesis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜