I am receiving this when i use 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!
As a background, I got these results from a single column in my database and am now trying to plot them using HighRoller/HighCharts.
Thanks for the help!
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.
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);
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
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.
<?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
}
}