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.

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services