I have an array:
$myArray = array('key1'=>'value1', 'key2'=>'value2');
I save it as a variable:
$fileContents = var_dump($myArray);
How can convert the variable back to use as a regular array?
echo $fileContents[0]; //output: value1
echo $fileContents[1]; //output: value2
The str_split() is an inbuilt function in PHP and is used to convert the given string into an array. This function basically splits the given string into smaller strings of length specified by the user and stores them in an array and returns the array.
Explode MethodPass a delimiter and a string to the explode function, and it splits the string into array elements, where it finds the delimiter. The delimiter can be a single character or it can be multiple characters.
The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function. If we have an array of elements, we can use the implode() function to join them all to form one string.
I think you might want to look into serialize
and unserialize
.
$myArray = array('key1'=>'value1', 'key2'=>'value2');
$serialized = serialize($myArray);
$myNewArray = unserialize($serialized);
print_r($myNewArray); // Array ( [key1] => value1 [key2] => value2 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With