I had an array that is separated by "|". What I wanted do was to separate it by this identifier.
The array is as follows:-
myid1|My Title|Detailed Description
myid2|My Title|Second Row Description
myid3|My Title|Third row description
What I did was that I just used explode on it to get my desired results.
$required_cells = explode('|', $bulk_array);
But the problem was that only my first array was properly exploded and the next first cell of the next array was mixed due to the "new line". Hence I couldn't use explode only.
To get the upper array in consecutive array cells as follows, I used the code below:- (with the help of this thread)
Array
(
[0] => myid1
[1] => My Title
[2] => Detailed Description
myid2
[3] => My Title
[4] => Second Row Description
myid3
[5] => My Title
[6] => Second Row Description
)
The working code:-
$str = "myid1|My Title|Detailed Description
myid2|My Title|Second Row Description
myid3|My Title|Third row description";
$newLine = (explode("\n", $str));
$result = array_map(function($someStr) {
return explode("|", $someStr);
}, $newLine);
print_r($result);
This worked perfectly but then the problem occured. This code works fine in PHP Version 5.4.10, but gives the following error in PHP Version 5.2.14. My dev server is 5.4.10 and unfortunately my production server is 5.2.14 therefore I need to fix this issue. The error is as follows:-
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in page.php on line 310