douren1891 2018-11-02 16:00
浏览 6
已采纳

我如何用php获取var中的对象

I use this wordpress function

$all_meta_for_user = get_user_meta( $user->ID );
$city = $all_meta_for_user['dokan_profile_settings'][0];
print_r( $city );

this what I get

a:11:{s:10:"store_name";s:14:"test_trioszhrt";s:6:"social";a:0:{}s:7:"payment";a:0:{}s:5:"phone";s:8:"12541025";s:10:"show_email";s:2:"no";s:7:"address";a:6:{s:8:"street_1";s:8:"kkloadaa";s:8:"street_2";s:0:"";s:4:"city";s:7:"tunisia";s:3:"zip";s:1:"1";s:7:"country";s:2:"NP";s:5:"state";s:3:"GAN";}s:8:"location";s:0:"";s:6:"banner";i:0;s:12:"find_address";s:0:"";s:14:"dokan_category";s:0:"";s:9:"store_ppp";i:10;}

I want to get only city? how I can do this?

  • 写回答

1条回答 默认 最新

  • douzi7890 2018-11-02 16:05
    关注

    This is a serialized string. unserialize it to a php value (in this case it is array) and use:

    $s = 'a:11:{s:10:"store_name";s:14:"test_trioszhrt";s:6:"social";a:0:{}s:7:"payment";a:0:{}s:5:"phone";s:8:"12541025";s:10:"show_email";s:2:"no";s:7:"address";a:6:{s:8:"street_1";s:8:"kkloadaa";s:8:"street_2";s:0:"";s:4:"city";s:7:"tunisia";s:3:"zip";s:1:"1";s:7:"country";s:2:"NP";s:5:"state";s:3:"GAN";}s:8:"location";s:0:"";s:6:"banner";i:0;s:12:"find_address";s:0:"";s:14:"dokan_category";s:0:"";s:9:"store_ppp";i:10;}';
    $data = unserialize($s);
    print_r($data);
    echo $data['address']['city'];
    

    Fiddle.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题