【问题标题】:getting value from stdclass object/array从 stdclass 对象/数组中获取值
【发布时间】:2017-10-06 03:08:27
【问题描述】:

我已经尝试了一段时间,现在试图从这个 std 对象中获取一个值

stdClass::__set_state(array(
   'regions' => 
  array (
    0 => 
    stdClass::__set_state(array(
       'id' => 1,
       'name' => 'Canada',
       'image_url' => 'https://s3-us-west-2.amazonaws.com/staticimageskiind/flags/CA@3x.png',
    )),
    1 => 
    stdClass::__set_state(array(
       'id' => 2,
       'name' => 'USA',
       'image_url' => 'https://s3-us-west-2.amazonaws.com/staticimageskiind/flags/US@3x.png',
    )),
    2 => 
    stdClass::__set_state(array(
       'id' => 3,
       'name' => 'Global',
       'image_url' => 'https://s3-us-west-2.amazonaws.com/staticimageskiind/flags/GLBL@3x.png',
    )),
    3 => 
    stdClass::__set_state(array(
       'id' => 4,
       'name' => 'Australia',
       'image_url' => 'https://s3-us-west-2.amazonaws.com/staticimageskiind/flags/AU@3x.png',
    )),
  ),
   'info' => 
  stdClass::__set_state(array(
     'code' => 'INFO_MARKETPLACE_RETRIEVED_REGIONS',
     'name' => 'Marketplace Regions Retrieved',
     'message' => 'A list of marketplace regions has been retrieved.',
  )),
));

但我似乎无法从该对象中获取值,不胜感激,我在网上搜索但找不到解决方案

【问题讨论】:

  • 我认为您使用的是 drupal ,请尝试使用 $VARIABLE->__get('regions');
  • 您尝试使用$object->regions 吗?如果不尝试提供有关您已经尝试过的更多信息。

标签: php arrays json stdclass


【解决方案1】:

你试过了吗:

echo $object->regions[0]->name;

例如?

【讨论】:

    【解决方案2】:

    我已经设法得到我想要的正确输出

    $abc = $result->regions;
    echo $abc[1]->name;
    

    希望对有需要的人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多