简体   繁体   English

访问PHP变量

[英]Accessing php variable

I can ask for help. 我可以寻求帮助。 When I print out the php array content: 当我打印出php数组内容时:

var_dump($ rowData);

I get an extract: 我得到了摘录:

 Array ( [0] =>   ) 
Array ( ) 
Array ( [0] => 162 [1] => 238 [2] => 331 [3] => 102 [4] => 103 [5] => 101 [6] => 99 [7] => 102 [8] => 103 [9] => 46 ) 
Array ( [0] => 53 [1] => 63 [2] => 48 [3] => 70 [4] => 30 [5] => 63 [6] => 63 [7] => 50 [8] => [9] => 33 ) 
array(4) { [0]=> array(1) { [0]=> string(6) " " } [1]=> array(0) { } [2]=> array(10) { [0]=> string(3) "162" [1]=> string(3) "238" [2]=> string(3) "331" [3]=> string(3) "102" [4]=> string(3) "103" [5]=> string(3) "101" [6]=> string(2) "99" [7]=> string(3) "102" [8]=> string(3) "103" [9]=> string(2) "46" } [3]=> array(10) { [0]=> string(2) "53" [1]=> string(2) "63" [2]=> string(2) "48" [3]=> string(2) "70" [4]=> string(2) "30" [5]=> string(2) "63" [6]=> string(2) "63" [7]=> string(2) "50" [8]=> string(0) "" [9]=> string(2) "33" } } 

How can I get into the variable: values 162 and 53 我如何进入变量:值162和53

I'm not sure what you need the first two rows, I think you should do some validation to make sure empty values don't get entered into the array if you don't need them. 我不确定前两行需要什么,我认为您应该进行一些验证,以确保不需要的空值不会输入到数组中。

But if you really want to use that array, and you need to access those specific values, you need to access it by index, the below snippet makes an array similar to yours, and you can see how I accessed the values you asked about in your question. 但是,如果您确实要使用该数组,并且需要访问这些特定值,则需要按索引访问它,下面的代码段使数组与您的数组相似,您可以看到我如何访问您在中查询的值你的问题。

<?php

//This is just to emulate the array you presented
$arr[][0] = null;
$arr[] = null;
$arr[][0] = 162;
$arr[][0] = 53;

var_dump($arr);

echo "first value you want: ".$arr[2][0];
echo "\nsecond value you want: ".$arr[3][0];

?>

here's a screenshot of the file running (also, if you want to see how to do something like this in a foreach loop and have a specific goal in mind with this, comment on my answer and I'll edit it). 这是正在运行的文件的屏幕截图(同样,如果您想查看如何在foreach循环中执行类似的操作,并有一个特定的目标,请评论我的答案,然后对其进行编辑)。

在此处输入图片说明

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

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