'How to separate h2 tag in array and value in another pos of array
Hi there i'm having problem to create an array in which the h2 will get in separte array pos and other below value in another position of array
<h2>While registration its showing email address already exists</h2>
<p>You can use one email address</p>
<h2>While registration its showing </h2>
<p>The usernames are unique.</p>
[{
'ques' = "How do I register?",
'ans' = "You can register in MachPrinciple.com"
},
{
'ques' = "While registration its showing email address already exists",
'ans' = "You can use one email address for creating a single profile. You can log in to your profile using the email address",
},
{
'ques' = "While registration its showing",
'ans' = "The usernames are unique. So if someone has already taken a username then you can't register using the same username"
}
]
Solution 1:[1]
Is this what you are looking for.
$input = [
"<h2>hi</h2>",
"<p>there</p>",
"<p>there</p>",
"<h2>hwo ar eyou</h2>",
"<p>Im' not bdoy</p>",
"<h2>is is good ? </h2>",
"<p>Not it is not</p>",
];
$outputArray = [];
$i= -1;
foreach($input as $in){
if (str_contains($in,'<h2>')){
$i++;
}
$outputArray[$i][] = $in;
}
This will be the output
[
[
"<h2>hi</h2>",
"<p>there</p>",
"<p>there</p>"
],
[
"<h2>hwo ar eyou</h2>",
"<p>Im' not bdoy</p>"
],
[
"<h2>is is good ? </h2>",
"<p>Not it is not</p>"
]
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shalini Singh |
