简体   繁体   English

PHP mysql数据库查询返回的数组中的单个值

[英]PHP echo single value from array returned by mysql database query

When I execute var_dump($row) in PHP script it returns this: 当我在PHP脚本中执行var_dump($row) ,它返回以下内容:

array(1) { ["rmb4"]=> string(2) "10" } 

How can I get the 10 out of that? 我怎样才能得到其中的10个? The return is from a SQL query. 返回来自SQL查询。 I just want some expression that will get 10 by itself so I can say $my_var=result of expression to get 10 by itselt. 我只想要一些表达式,其自身将得到10,所以我可以说$ my_var =表达式的结果将由elselt得到10。

This should work: 这应该工作:

echo $row['rmb4'];

Explanation: 说明:

If you need a key from an array, which is recognizable by the arrow => , you will have to do: $array['key'] 如果您需要数组中的键(可以通过箭头=>识别),则必须这样做: $array['key']

If you need a object from a array you will need to this: $array->object 如果需要数组中的对象,则需要: $array->object

A combination is also possible. 也可以组合。 That would be: $array['key']->object 那将是: $array['key']->object

<?php
  $row = array('rmb4'=>10);
  var_dump($row);

  echo $row['rmb4'];
?>

Output 输出量

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM