Get the nth element from array_chunk returned results
up vote
-1
down vote
favorite
I have a very large array which I have split with array_chunk
into six, I'm looking to get remove/access
the 5th (all for the price) item in every chunk. Here are 2 of many chunks
Array
(
[0] => Scottsdale
[1] => Santa Ana John Wayne Airport
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $10 980)
)
Array
(
[0] => Milwaukee Mitchell Intl
[1] => Chicago Midway International
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $6 300)
)
php arrays
add a comment |
up vote
-1
down vote
favorite
I have a very large array which I have split with array_chunk
into six, I'm looking to get remove/access
the 5th (all for the price) item in every chunk. Here are 2 of many chunks
Array
(
[0] => Scottsdale
[1] => Santa Ana John Wayne Airport
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $10 980)
)
Array
(
[0] => Milwaukee Mitchell Intl
[1] => Chicago Midway International
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $6 300)
)
php arrays
1
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?
– Alive to Die
Nov 12 at 11:44
1
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a very large array which I have split with array_chunk
into six, I'm looking to get remove/access
the 5th (all for the price) item in every chunk. Here are 2 of many chunks
Array
(
[0] => Scottsdale
[1] => Santa Ana John Wayne Airport
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $10 980)
)
Array
(
[0] => Milwaukee Mitchell Intl
[1] => Chicago Midway International
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $6 300)
)
php arrays
I have a very large array which I have split with array_chunk
into six, I'm looking to get remove/access
the 5th (all for the price) item in every chunk. Here are 2 of many chunks
Array
(
[0] => Scottsdale
[1] => Santa Ana John Wayne Airport
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $10 980)
)
Array
(
[0] => Milwaukee Mitchell Intl
[1] => Chicago Midway International
[2] => Cessna C750 Citation X
[3] => 8
[4] => Mon Nov 12 00:00:00 GMT 2018
[5] => Call for Price (Was $6 300)
)
php arrays
php arrays
edited Nov 12 at 11:44
Gufran Hasan
3,25831225
3,25831225
asked Nov 12 at 11:40
kariuki
11
11
1
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?
– Alive to Die
Nov 12 at 11:44
1
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10
add a comment |
1
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?
– Alive to Die
Nov 12 at 11:44
1
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10
1
1
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?– Alive to Die
Nov 12 at 11:44
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?– Alive to Die
Nov 12 at 11:44
1
1
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
1. If you want to access them and put them into separate array then use array_column()
$price_array = array_column($array,5);
print_r($price_array);
Output:-https://3v4l.org/1slp0
2. If you want to access them for printing purpose then use foreach()
foreach($array as $arr){
echo $arr[5].PHP_EOL;
}
Output:-https://3v4l.org/NXVEb
3. If you want to remove them then again use foreach()
foreach($array as &$arr){
unset($arr[5]);
}
Output:-https://3v4l.org/W5WYO
4. if you want to remove that value from child array as well as want to print then use unset() and print_r() along with foreach()
foreach ($array as $arr) {
unset($arr[5]); //this will not remove the value from original array
echo "<pre/>";print_r($arr);
}
Output:- https://3v4l.org/Td4u3
Reference:- Passing by Reference
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
add a comment |
up vote
-4
down vote
I solved it:-
foreach ($myrows as $myrows) {
unset($myrows[5]);
echo "<pre>";
print_r($myrows);
echo "</pre>";
}
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
1. If you want to access them and put them into separate array then use array_column()
$price_array = array_column($array,5);
print_r($price_array);
Output:-https://3v4l.org/1slp0
2. If you want to access them for printing purpose then use foreach()
foreach($array as $arr){
echo $arr[5].PHP_EOL;
}
Output:-https://3v4l.org/NXVEb
3. If you want to remove them then again use foreach()
foreach($array as &$arr){
unset($arr[5]);
}
Output:-https://3v4l.org/W5WYO
4. if you want to remove that value from child array as well as want to print then use unset() and print_r() along with foreach()
foreach ($array as $arr) {
unset($arr[5]); //this will not remove the value from original array
echo "<pre/>";print_r($arr);
}
Output:- https://3v4l.org/Td4u3
Reference:- Passing by Reference
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
add a comment |
up vote
2
down vote
1. If you want to access them and put them into separate array then use array_column()
$price_array = array_column($array,5);
print_r($price_array);
Output:-https://3v4l.org/1slp0
2. If you want to access them for printing purpose then use foreach()
foreach($array as $arr){
echo $arr[5].PHP_EOL;
}
Output:-https://3v4l.org/NXVEb
3. If you want to remove them then again use foreach()
foreach($array as &$arr){
unset($arr[5]);
}
Output:-https://3v4l.org/W5WYO
4. if you want to remove that value from child array as well as want to print then use unset() and print_r() along with foreach()
foreach ($array as $arr) {
unset($arr[5]); //this will not remove the value from original array
echo "<pre/>";print_r($arr);
}
Output:- https://3v4l.org/Td4u3
Reference:- Passing by Reference
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
add a comment |
up vote
2
down vote
up vote
2
down vote
1. If you want to access them and put them into separate array then use array_column()
$price_array = array_column($array,5);
print_r($price_array);
Output:-https://3v4l.org/1slp0
2. If you want to access them for printing purpose then use foreach()
foreach($array as $arr){
echo $arr[5].PHP_EOL;
}
Output:-https://3v4l.org/NXVEb
3. If you want to remove them then again use foreach()
foreach($array as &$arr){
unset($arr[5]);
}
Output:-https://3v4l.org/W5WYO
4. if you want to remove that value from child array as well as want to print then use unset() and print_r() along with foreach()
foreach ($array as $arr) {
unset($arr[5]); //this will not remove the value from original array
echo "<pre/>";print_r($arr);
}
Output:- https://3v4l.org/Td4u3
Reference:- Passing by Reference
1. If you want to access them and put them into separate array then use array_column()
$price_array = array_column($array,5);
print_r($price_array);
Output:-https://3v4l.org/1slp0
2. If you want to access them for printing purpose then use foreach()
foreach($array as $arr){
echo $arr[5].PHP_EOL;
}
Output:-https://3v4l.org/NXVEb
3. If you want to remove them then again use foreach()
foreach($array as &$arr){
unset($arr[5]);
}
Output:-https://3v4l.org/W5WYO
4. if you want to remove that value from child array as well as want to print then use unset() and print_r() along with foreach()
foreach ($array as $arr) {
unset($arr[5]); //this will not remove the value from original array
echo "<pre/>";print_r($arr);
}
Output:- https://3v4l.org/Td4u3
Reference:- Passing by Reference
edited Nov 13 at 7:08
answered Nov 12 at 11:51
Alive to Die
55k82868
55k82868
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
add a comment |
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
Thanks i will try it out but i have found another way
– kariuki
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
@kariuki check my currently edited solution
– Alive to Die
Nov 12 at 11:54
add a comment |
up vote
-4
down vote
I solved it:-
foreach ($myrows as $myrows) {
unset($myrows[5]);
echo "<pre>";
print_r($myrows);
echo "</pre>";
}
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
add a comment |
up vote
-4
down vote
I solved it:-
foreach ($myrows as $myrows) {
unset($myrows[5]);
echo "<pre>";
print_r($myrows);
echo "</pre>";
}
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
add a comment |
up vote
-4
down vote
up vote
-4
down vote
I solved it:-
foreach ($myrows as $myrows) {
unset($myrows[5]);
echo "<pre>";
print_r($myrows);
echo "</pre>";
}
I solved it:-
foreach ($myrows as $myrows) {
unset($myrows[5]);
echo "<pre>";
print_r($myrows);
echo "</pre>";
}
edited Nov 13 at 4:39
Alive to Die
55k82868
55k82868
answered Nov 12 at 11:52
kariuki
11
11
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
add a comment |
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
1
1
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
Wow you must have tried really hard before posting the question. I mean 10 minutes later you have a working code.
– Andreas
Nov 12 at 12:08
1
1
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
@Andreas lot of magic happens on stack now a days.
– Alive to Die
Nov 12 at 12:18
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
array_chunk($rows,10,false);
– kariuki
Nov 13 at 14:22
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
Very cheeky @Andrea the reason it dint work i was using array_chunk($rows,10,true); somewhere in the code instead of array_chunk($rows,10,false ); that way i could not get to the item . i changed to false and then pasted the array here before tasting it , then realized the array keys have changed and can easily accessed .
– kariuki
Nov 13 at 14:34
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261397%2fget-the-nth-element-from-array-chunk-returned-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I'm looking to get remove/access the 5th (all for the price) item in every chunk
-> in an array or just want to print through loop?– Alive to Die
Nov 12 at 11:44
1
foreach(array_chunk($arr, 6) as $a) { echo $a[5]; }
– Federico klez Culloca
Nov 12 at 11:44
So do you want to access them or remove them?
– iainn
Nov 12 at 11:46
I wanted to access them bthatnks i found an easier way
– kariuki
Nov 12 at 11:55
@kariuki it's your responsibility to mark an answer as accepted answer if you got the solution.
– Alive to Die
Nov 13 at 7:10