I'm not sure if my memory is wrong, but when I last used PHP (years ago), I vaguely remember doing something like this:
$firstVariable, $secondVariable = explode(' ', 'Foo Bar');
Note that the above is incorrect syntax, however in this example it would assign 'Foo' to $firstVariable, and 'Bar' to $secondVariable.
What is the correct syntax for this?
Thanks.
Yes, you can store variables within arrays, though you'll need to remove the space between $result and the opening bracket.
Given two array arr1 and arr2 and the task is to append one array to another array. Using array_merge function: This function returns a new array after merging the two arrays. $arr1 = array ( "Geeks" , "g4g" );
The list() function is used to assign values to a list of variables in one operation. Note: Prior to PHP 7.1, this function only worked on numerical arrays.
list($firstVar, $secondVar) = explode(' ', 'Foo Bar');
list() is what you are after.
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