I want to explode a string with different kind of characters.
I already know how to explode a string, I also think I know how I can do it in different levels.
How do you use one of the values as name ($var['name']) instead of having numbers ($var[0])?
I only know how to do this manually in the array, but I don't know how to add it with variables.
In summary I want this string:
title:hello;desc:message|title:lorem;desc:ipsum;ids:1,2,3
to become this array:
[
[
'title' => 'hello',
'desc' => 'message',
],
[
'title' => 'lorem',
'desc' => 'ipsum',
'ids' => ['1', '2', '3'],
],
]
Edit: I made some progress, but it's not quite finished.
<?php
$string = "title:hello;desc:message|title:lorem;desc:ipsum;ids:1,2,3";
$string = explode("|", $string);
foreach($string as $split){
$split = explode(";", $split);
foreach($split as $split2){
$split2 = explode(":", $split2);
// more code..
}
}
Now I need $split2[0] to be the name and $split2[1] to be the value, like the example earlier.
It returns:
And then process your 'ids' index