dongqiao3833 2017-08-06 07:47
浏览 231
已采纳

php:如何从对象中获取名称

this might be very simple, and well, yes ... I may not fully understand how objects work, which seems to be the real problem here. So thanks for helping! ^^

I've got an Object that kinda looks like this.

$myobject = Array( [some_random_name] => "Value to that random name" )

Since I'm not sure how those two bits of information are called (sry for that) I will refer to them as "name" and "value". My question is: how do I extract these informations? I need both, the "name" and the "value", so I can store them in two variables ($namevar, $nameval), which should then output something like this:

echo($namevar) = "some_random_name"

echo($nameval) = "Value to that random name"

Thanks.

  • 写回答

3条回答 默认 最新

  • douxianji6104 2017-08-06 07:53
    关注

    well, you are using an Array, not an object. in order to get the array keys or values, you could use the following functions: array_values & array_keys.

    i could add code snippets etc, but its really straight forward in php's docs:

    you could also possibly iterate the array or object (works the same for both), using something like the following code:

    foreach($object as $key => $value) { ... }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化