I’m just optimising my code and if there is a function that does something like this, i can get rid of my own
There are duplicates for parsing query strings but the string I’m paring is in this format:
$string = "cheese/camel/egg/cream";
is there a php function whereby I can parse this into an associative array?
Lets say if I were to define the array with keys like:
$keys = array( "val1", "val2", "val3", "val4" );
is there a php function to parse the string into these variables? Something like:
$associative_array = magic_function($keys, $string, $delimiter);
to end up with something like this:
array(4) {
"var1" => "cheese",
"var2" => "camel",
"var3" => "egg",
"var4" => "cream"
}
PHP provides many simple functions, you just have to use them together:
Reference:
array_combine,explodeMore array and string functions.