Method: 1. Use "array_merge (array 1, array 2...)" to merge one or more arrays into one array; 2. Use "implode (merge array)" to convert the merged array into String; 3. Use "settype (string, type identifier)" to convert the string to the specified numerical type (integer or floating point number).
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use array_merge () merge the arrays, and then convert the array type to a numeric type.
Step 1: Use array_merge() to merge arrays
The array_merge() function is used to merge one or more arrays into one array.
Note: If two or more array elements have the same key name, the last element will overwrite the other elements.
Step 2: Use the implode() function to convert the merged array into a string
implode() function can convert a Convert one-dimensional array to string
$str=implode($arr); var_dump($str);
Step 3: Use settype() to convert the string to numeric type
settype ($var,$type)
Used to set the variable $var to the specified $type type.
The numeric type can be set when $type is set to the following characters
"integer" (or "int", starting from PHP 4.2.0)
"float" (only available after PHP 4.2.0, "double" used in older versions is now deprecated)
settype($str,"int"); var_dump($str); settype($str,"float"); var_dump($str);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to merge arrays and convert them into numeric types in php. For more information, please follow other related articles on the PHP Chinese website!