从阵列获取的价值 [英] Get value from a array

查看:81
本文介绍了从阵列获取的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新

我怎么能检索此值?我需要做的,如果我将值写入我的数据库。

 阵列(3){
 [1] =>空值 [2] =>阵列(2){    [123] =>    INT(123)    [122] =>    INT(0)  } [3] =>空值}


解决方案

有一些是在你的输出失踪。我认为它看起来是这样的:

  //的var_dump($数组);
阵列(1){
  [0] =>
  字符串(2)39
}

因此​​,您可以访问 $数组值[0] 。简单数组访问。

由于数组在PHP中最重要的数据结构,你应该学会如何对付他们。结果
阅读 PHP:数组

更新:

关于你的更新,你想要哪个值?你有一个多维数组。这是你会得到什么:

  $阵列[1] //给空
$阵列[2] //给出一个数组
$阵列[2] [123] //给出整数123
$阵列[2] [122] //给出整数0
$阵列[3] //给空

也许你也想(有)循环内阵列上获得的所有值:

 的foreach($数组[2] $关键=> $值){
    //使用$键和$有价值的东西
}

正如我所说的,阅读文档,它包含了你需要知道的一切。在PHP访问数组并不比其他编程语言非常不同。

PHP手册包含了很多的例子,它是pretty能文档。使用它!

update

how can I retrieve this value? I need to do that if I will write the value to my database.

array(3) {
 [1]=> NULL  

 [2]=> array(2) {

    [123]=>

    int(123)

    [122]=>

    int(0)

  }

 [3]=> NULL

}

解决方案

There is something missing in your output. I assume it looks something like:

// var_dump($array);
array(1) {
  [0]=>
  string(2) "39"
}

so you can access the value with $array[0]. Simple array access.

As arrays are the most important data structure in PHP, you should learn how to deal with them.
Read PHP: Arrays.

Update:

Regarding your update, which value do you want? You have a multidimensional array. This is what you will get:

$array[1] // gives null
$array[2] // gives an array
$array[2][123] // gives the integer 123
$array[2][122] // gives the integer 0
$array[3] // gives null

Maybe you also want (have) to loop over the inner array to get all values:

foreach($array[2] as $key => $value) {
    // do something with $key and $value
}

As I said, read the documentation, it contains everything you need to know. Accessing arrays in PHP is not much different than in other programming languages.

The PHP manual contains a lot of examples, it is a pretty could documentation. Use it!

这篇关于从阵列获取的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆