[英]Need help pulling just one value from a multi-dimensional associative array
Sorry if this is a pretty dumb question, but I'm a PHP novice. 对不起,如果这是一个非常愚蠢的问题,但我是一个PHP新手。 I'm storing the results of a query in one element of an associative array ($result["data"]).
我将查询结果存储在关联数组的一个元素中($ result [“data”])。 The data looks something like this:
数据看起来像这样:
id f1 f2 f3
143 1 21 33
143 312 31 4433
143 22 312 412
The id field is guaranteed to store the same value for all elements of the array. 保证id字段为数组的所有元素存储相同的值。 I want to store that value (143 in the above sample table) in a variable.
我想将该值(上面的示例表中的143)存储在变量中。 I've tried things along the lines of $result["data"]["id"][0], but nothing I try seems to work.
我已尝试过$ result [“data”] [“id”] [0]的行,但我尝试的任何东西似乎都无效。 I know there's probably a really simple way to do this.
我知道这可能是一个非常简单的方法。 What is it?
它是什么?
试试:
$id = $result['data'][0]['id'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.