I am receiving this when i use print_r:
当我使用print_r时,我收到了这个:
Array (
[0] => 15
[1] => 15
[2] => 15
[3] => 15
[4] => 15
[5] => 16
[6] => 15
[7] => 15
[8] => 15
[9] => 14
... and so on ...
)
and I was wondering how I can get an array of these second values (i.e.):
我想知道如何获得这些第二个值的数组(即):
$newArray = array(15,15,15,15,15,16,15,15,15,14, ... );
I have tried using array_values but to no avail!
我尝试过使用array_values但无济于事!
As a background, I got these results from a single column in my database and am now trying to plot them using HighRoller/HighCharts.
作为背景,我从我的数据库中的单个列获得了这些结果,现在我正在尝试使用HighRoller / HighCharts绘制它们。
Thanks for the help!
谢谢您的帮助!
3 个解决方案
#1
3
You don't have an array of arrays. You have an array of values with numeric indexes. Unless I am totally misunderstanding your question ....
您没有阵列数组。您有一个带有数字索引的值数组。除非我完全误解你的问题....
Array (
[0] => 15
[1] => 15
[2] => 15
[3] => 15
[4] => 15
[5] => 16
[6] => 15
[7] => 15
[8] => 15
[9] => 14
... and so on ...
)
This means your array at index 0 has value 15 and so on.
这意味着索引0处的数组值为15,依此类推。
#2
0
the "second values" are the values of the array... the square bracket numbers are the indexes. you simply access them with $array_name[0]
or $array_name[5]
or foreach($array_name as $idx => $val) echo($val);
“第二个值”是数组的值...方括号是索引。您只需使用$ array_name [0]或$ array_name [5]或foreach($ array_name as $ idx => $ val)echo($ val)访问它们;
#3
0
As others have said, what you are showing is not a multi-dimensional array.
正如其他人所说,你所展示的不是一个多维数组。
A multi-dimensional array would look something like this when var_dumped
当var_dumped时,多维数组看起来像这样
array(3) {
[0] =>
array(1) {
[0] =>
int(15)
}
[1] =>
array(1) {
[0] =>
int(15)
}
[2] =>
array(1) {
[0] =>
int(15)
}
}
To answer the question even though it doesn't look like what you have, for each level of a multi-dimensional array you can use an embedded foreach() loop.
要回答这个问题,即使它看起来不像你所拥有的,对于多维数组的每个级别,你都可以使用嵌入的foreach()循环。
<?php
$myArray = [
[15],
[15],
[15],
];
var_dump($myArray);//outputs above example
foreach($myArray as $arr) {
foreach($arr as $val) {
echo $val;//outputs the value of each array inside the outer array
}
}
#1
3
You don't have an array of arrays. You have an array of values with numeric indexes. Unless I am totally misunderstanding your question ....
您没有阵列数组。您有一个带有数字索引的值数组。除非我完全误解你的问题....
Array (
[0] => 15
[1] => 15
[2] => 15
[3] => 15
[4] => 15
[5] => 16
[6] => 15
[7] => 15
[8] => 15
[9] => 14
... and so on ...
)
This means your array at index 0 has value 15 and so on.
这意味着索引0处的数组值为15,依此类推。
#2
0
the "second values" are the values of the array... the square bracket numbers are the indexes. you simply access them with $array_name[0]
or $array_name[5]
or foreach($array_name as $idx => $val) echo($val);
“第二个值”是数组的值...方括号是索引。您只需使用$ array_name [0]或$ array_name [5]或foreach($ array_name as $ idx => $ val)echo($ val)访问它们;
#3
0
As others have said, what you are showing is not a multi-dimensional array.
正如其他人所说,你所展示的不是一个多维数组。
A multi-dimensional array would look something like this when var_dumped
当var_dumped时,多维数组看起来像这样
array(3) {
[0] =>
array(1) {
[0] =>
int(15)
}
[1] =>
array(1) {
[0] =>
int(15)
}
[2] =>
array(1) {
[0] =>
int(15)
}
}
To answer the question even though it doesn't look like what you have, for each level of a multi-dimensional array you can use an embedded foreach() loop.
要回答这个问题,即使它看起来不像你所拥有的,对于多维数组的每个级别,你都可以使用嵌入的foreach()循环。
<?php
$myArray = [
[15],
[15],
[15],
];
var_dump($myArray);//outputs above example
foreach($myArray as $arr) {
foreach($arr as $val) {
echo $val;//outputs the value of each array inside the outer array
}
}