如何从这个数组中获取单个值

时间:2012-10-24 09:41:44

标签: php codeigniter

当我打印数组print_r($ post)时,我得到了这个结果;

Array ( [0] => Array ( [0] => stdClass Object ( [subscriber_id] => 80010055 [cto_id] => [name] => n [mobile] => 1234564444 [state] => [city] => fsd [cto_subscriber_id] => 0 [password] => e10adc3949ba59abbe56e057f20f883e [email] => n@n.com [email_verified] => 1 [ip_address] => ::1 [last_login_time] => 2012-10-24 11:37:19 ) ) [1] => Array ( [0] => stdClass Object ( [subscriber_id] => 80010055 [ip_address] => [landline_number] => [sex] => 0 [dob] => 0000-00-00 00:00:00 [marital_status] => hfg [state] => [addres] => fgh [city] => fghfg [pincode] => fghfgh ) ) ) 

如何获得单个值

3 个答案:

答案 0 :(得分:2)

Typecast它到阵列?

$arr = (array)$post[0][0];

然后你将能够通过正常数组

循环它
foreach ($arr as $key => $value){....}

答案 1 :(得分:1)

foreach $post as $sub {
    foreach $sub as $single {
        echo $single;
    }
}

答案 2 :(得分:1)

认为您应首先了解arraysobjects的基础知识。 无论如何,为了获得let say subscriber_id的值,你应该使用以下内容:

$post[0][0]->subscriber_id

首先进入数组,然后从Object

中获取值