I have an array like this
on;tracking34567;1;ABC;2019-08-13;on;tracking123;1;BCD;2019-08-13;on;123456test;1;USA;2019-08-13;
How to split it like this
Array
(
[0] => on
[1] => tracking34567
[2] => 1
[3] => ABC
[4] => 2019-08-13
)
Array
(
[0] => on
[1] => tracking123
[2] => 1
[3] => BCD
[4] => 2019-08-13
)
Array
(
[0] => on
[1] => 123456test
[2] => 1
[3] => USA
[4] => 2019-08-13
)
Please help me
UPDATE
I tryed but it show
public function indexAction()
{
$data = $this->getRequest()->getParam("values");
$temp = explode(";",$string);
$i = 0;
$result = array();
foreach($temp as $v){
if($v == "on"){
$i++;
}
$result[$i][] = $v;
}
print_r($result);exit;
// var_dump($data);exit;
}
UPDATE
It work fine, but if i need array like this, how to change it?
Array
(
[a] => on
[b] => tracking34567
[c] => 1
[d] => ABC
[e] => 2019-08-13
)
Array
(
[a] => on
[b] => tracking123
[c] => 1
[d] => BCD
[e] => 2019-08-13
)
Array
(
[a] => on
[b] => 123456test
[c] => 1
[d] => USA
[e] => 2019-08-13
)
6
Answers
You can use as below:
You first need to convert whole string in array
Now use this temp array to create your new array
You will have your result in
$result
Can you please try this it will help you.
You can try this
Try this
If values in your string always comes in the same format and there are always five element in the string, then you can do it in a much better and simpler way, rather then using loops.
You can use php in-built functions and achieve it.
Here have a look at the code.
Hope this helps.Thanks