split a single array based on specific inner array valueSecure hash and salt for PHP passwordsHow to insert an item into an array at a specific index (JavaScript)?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueDetermine whether an array contains a valueCheck if a value exists in an array in RubyHow to Sort Multi-dimensional Array by Value?Reference — What does this symbol mean in PHP?PHP array delete by value (not key)Copy array by value
What is the minimum required technology to reanimate someone who has been cryogenically frozen?
What is a good way to allow only one non null field in an object
Is there an idiom that means "revealing a secret unintentionally"?
Employee is self-centered and affects the team negatively
Is it a good idea to copy a trader when investing?
Lorentz invariance of Maxwell's equations in matter
Identity of a supposed anonymous referee revealed through "Description" of the report
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Has everyone forgotten about wildfire?
Double underlining a result in a system of equations with calculation steps on the right side
How likely are Coriolis-effect-based quirks to develop in starship crew members?
What is the radius of the circle in this problem?
What dice to use in a game that revolves around triangles?
Are wands in any sort of book going to be too much like Harry Potter?
How can I make parentheses stick to formula?
Was Mohammed the most popular first name for boys born in Berlin in 2018?
Does a surprised creature obey the 1st level spell Command?
What does the "DS" in "DS-..." US visa application forms stand for?
Not taking the bishop by the knight, why?
Using wilcox.test() and t.test() in R yielding different p-values
Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?
Locked my sa user out
Is there a need for better software for writers?
How to handle DM constantly stealing everything from sleeping characters?
split a single array based on specific inner array value
Secure hash and salt for PHP passwordsHow to insert an item into an array at a specific index (JavaScript)?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueDetermine whether an array contains a valueCheck if a value exists in an array in RubyHow to Sort Multi-dimensional Array by Value?Reference — What does this symbol mean in PHP?PHP array delete by value (not key)Copy array by value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
$data =
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
.............
[17] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
)
I am trying to split an array to different arrays based on values. This is my array. I need split a single array into multiple based on inner value "CITY :"
count all "CITY :" and split array from first "CITY" to NEXT "CITY" AND NEXT....
result:
I want to split the array based on value like below
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
)
[2] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
i have no idea how to split this
php jquery html arrays columnsorting
add a comment |
$data =
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
.............
[17] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
)
I am trying to split an array to different arrays based on values. This is my array. I need split a single array into multiple based on inner value "CITY :"
count all "CITY :" and split array from first "CITY" to NEXT "CITY" AND NEXT....
result:
I want to split the array based on value like below
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
)
[2] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
i have no idea how to split this
php jquery html arrays columnsorting
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03
add a comment |
$data =
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
.............
[17] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
)
I am trying to split an array to different arrays based on values. This is my array. I need split a single array into multiple based on inner value "CITY :"
count all "CITY :" and split array from first "CITY" to NEXT "CITY" AND NEXT....
result:
I want to split the array based on value like below
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
)
[2] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
i have no idea how to split this
php jquery html arrays columnsorting
$data =
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
.............
[17] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
)
I am trying to split an array to different arrays based on values. This is my array. I need split a single array into multiple based on inner value "CITY :"
count all "CITY :" and split array from first "CITY" to NEXT "CITY" AND NEXT....
result:
I want to split the array based on value like below
[1] => Array
(
[1] => CITY :
[3] => CANADA
)
[8] => Array
(
[1] => Customer :
[4] => CUS1
)
[9] => Array
(
[1] => Customer :
[4] => CUS2
)
[10] => Array
(
[1] => Customer :
[4] => CUS3
)
)
[2] => Array
(
[1] => CITY :
[3] => FLORIDA
)
[18] => Array
(
[1] => Customer :
[3] => C2
)
i have no idea how to split this
php jquery html arrays columnsorting
php jquery html arrays columnsorting
asked Mar 23 at 8:49
user11246426user11246426
73
73
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03
add a comment |
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03
add a comment |
1 Answer
1
active
oldest
votes
this should work for you:
<?php
$data = array(
array(
'CITY :',
'CANADA'
),
array(
'Customer :',
'CUS1'
),
array(
'Customer :',
'CUS2'
),
array(
'Customer :',
'CUS3'
),
array(
'CITY :',
'FLORIDA'
),
array(
'Customer :',
'C2'
),
);
$result = array();
$firstRun = true;
foreach($data as $item)
if(array_values($item)[0] == 'CITY :')
if(!$firstRun)
$result[] = $splittedArray;
else
$firstRun = false;
$splittedArray = array();
$splittedArray[] = $item;
// add last array, as it will not pass at the finish through the first logic of the loop
$result[] = $splittedArray;
print_r($result);
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55312103%2fsplit-a-single-array-based-on-specific-inner-array-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
this should work for you:
<?php
$data = array(
array(
'CITY :',
'CANADA'
),
array(
'Customer :',
'CUS1'
),
array(
'Customer :',
'CUS2'
),
array(
'Customer :',
'CUS3'
),
array(
'CITY :',
'FLORIDA'
),
array(
'Customer :',
'C2'
),
);
$result = array();
$firstRun = true;
foreach($data as $item)
if(array_values($item)[0] == 'CITY :')
if(!$firstRun)
$result[] = $splittedArray;
else
$firstRun = false;
$splittedArray = array();
$splittedArray[] = $item;
// add last array, as it will not pass at the finish through the first logic of the loop
$result[] = $splittedArray;
print_r($result);
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
add a comment |
this should work for you:
<?php
$data = array(
array(
'CITY :',
'CANADA'
),
array(
'Customer :',
'CUS1'
),
array(
'Customer :',
'CUS2'
),
array(
'Customer :',
'CUS3'
),
array(
'CITY :',
'FLORIDA'
),
array(
'Customer :',
'C2'
),
);
$result = array();
$firstRun = true;
foreach($data as $item)
if(array_values($item)[0] == 'CITY :')
if(!$firstRun)
$result[] = $splittedArray;
else
$firstRun = false;
$splittedArray = array();
$splittedArray[] = $item;
// add last array, as it will not pass at the finish through the first logic of the loop
$result[] = $splittedArray;
print_r($result);
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
add a comment |
this should work for you:
<?php
$data = array(
array(
'CITY :',
'CANADA'
),
array(
'Customer :',
'CUS1'
),
array(
'Customer :',
'CUS2'
),
array(
'Customer :',
'CUS3'
),
array(
'CITY :',
'FLORIDA'
),
array(
'Customer :',
'C2'
),
);
$result = array();
$firstRun = true;
foreach($data as $item)
if(array_values($item)[0] == 'CITY :')
if(!$firstRun)
$result[] = $splittedArray;
else
$firstRun = false;
$splittedArray = array();
$splittedArray[] = $item;
// add last array, as it will not pass at the finish through the first logic of the loop
$result[] = $splittedArray;
print_r($result);
this should work for you:
<?php
$data = array(
array(
'CITY :',
'CANADA'
),
array(
'Customer :',
'CUS1'
),
array(
'Customer :',
'CUS2'
),
array(
'Customer :',
'CUS3'
),
array(
'CITY :',
'FLORIDA'
),
array(
'Customer :',
'C2'
),
);
$result = array();
$firstRun = true;
foreach($data as $item)
if(array_values($item)[0] == 'CITY :')
if(!$firstRun)
$result[] = $splittedArray;
else
$firstRun = false;
$splittedArray = array();
$splittedArray[] = $item;
// add last array, as it will not pass at the finish through the first logic of the loop
$result[] = $splittedArray;
print_r($result);
answered Mar 23 at 9:02
Adrian CarageaAdrian Caragea
1098
1098
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
add a comment |
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Looks good, but include some more explanation to your code. OP should understand what you are doing in the code.
– Andreas
Mar 23 at 9:17
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
Thank you @Andreas, I will add more comments to explain it next time. Here is a short explanation in order to provide more details: the code takes your data set, iterates through it, checks when "CITY :" is found and creates a new array (a split one), when the next "CITY :" is reached the code determines that a new segment starts so a new split array is created, adding the last one to the result data set.
– Adrian Caragea
Mar 23 at 13:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55312103%2fsplit-a-single-array-based-on-specific-inner-array-value%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
can you give this array in json format? so we can try it on our end
– M.Hemant
Mar 23 at 8:55
This question lacks any code to show us that you've made any attempt to solve this yourself. If you've tried something, show us what you've tried, example of the expected output and what you're actually getting. If you haven't tried anything, you need to do that before posting. We can help you with your existing code, but we won't write it for you. Please read: How to create a Minimal, Complete, and Verifiable example and also How do I ask a good question?
– Magnus Eriksson
Mar 23 at 9:03