Home php教程 php手册 改写函数实现PHP二维/三维数组转字符串

改写函数实现PHP二维/三维数组转字符串

Jun 06, 2016 pm 08:27 PM
three dimensional array Two-dimensional array Array to string

将多维数组中所有的数值转换成字符串最多支持三维数组,在给定的示例函数基础上改写出了的,感兴趣的朋友可以参考下,希望对大家有所帮助

由于工作需要,自己在手册给定的示例函数基础上改写出了这样一个函数,代码如下:

复制代码 代码如下:


//将多维数组中所有的数值转换成字符串————》最多支持三维数组
function implodex( $glue, $array, $separator='' ) {
if ( ! is_array( $array ) ) return $array;
$string = array();

$count = 0;
foreach ( $array as $key => $val ) {
if ( is_array( $val ) )
$val = implode( $glue, $val );

if($count == 0){
$string[] = "{$val}";
}else{
$string[] = "{$glue}{$val}";
}
}

if(empty($separator))$separator = $glue;

return implode( $separator, $string );
}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert a two-dimensional php array into a one-dimensional array How to convert a two-dimensional php array into a one-dimensional array Aug 03, 2023 am 11:14 AM

How to convert a php array from two dimensions to a one-dimensional array: 1. Use loop traversal to traverse the two-dimensional array and add each element to the one-dimensional array; 2. Use the "array_merge" function to merge multiple arrays into An array. Pass the two-dimensional array as a parameter to the "array_merge" function to convert it into a one-dimensional array; 3. Using the "array_reduce" function, you can process all the values ​​in the array through a callback function and finally return a result.

How to use the array_sum function in PHP to calculate the sum of elements in a column of a two-dimensional array How to use the array_sum function in PHP to calculate the sum of elements in a column of a two-dimensional array Jun 26, 2023 pm 12:45 PM

In PHP programming, the array_sum function is a very practical function that can calculate the sum of all elements in an array. However, when we need to calculate the sum of a column of elements in a two-dimensional array, we may encounter some trouble. This article will introduce how to use the array_sum function in PHP to calculate the sum of elements in a column of a two-dimensional array. First, we need to understand the concept of two-dimensional arrays. A two-dimensional array is an array containing multiple arrays, which can be regarded as a table. Each array represents a table

How to get the value of a specified column in a two-dimensional array using the array_column function in PHP How to get the value of a specified column in a two-dimensional array using the array_column function in PHP Jun 26, 2023 pm 01:32 PM

In PHP programming, we often need to operate on arrays, including obtaining the value of a specified column. PHP provides a very convenient function - array_column, which can help us quickly obtain the value of a specified column in a two-dimensional array. This article will introduce how to use the array_column function. Basic usage of array_column function: array_column(array$array,mixed$column_key[

How to reverse a two-dimensional array in php How to reverse a two-dimensional array in php Dec 26, 2022 am 09:38 AM

How to reverse a two-dimensional array in php: 1. Create a php sample file; 2. Define a two-dimensional array; 3. Reverse the array through the "array_reverse($a,true);" function; 4. Use "print_r" to print Just reverse the two-dimensional array.

Python program to convert array to string and concatenate elements using specified characters Python program to convert array to string and concatenate elements using specified characters Sep 13, 2023 pm 10:41 PM

An array is a data structure consisting of a collection of elements of the same data type, with each element identified by an index. [2,4,0,5,8] Arrays in Python Python does not have its own data structure to represent arrays. Instead, we can use a list data structure to represent an array. Here we will list an array using - [10,4,11,76,99] In this post we will write a Python program to convert an array to string and concatenate the elements using specified characters . Input-Output Scenario Suppose we have an input array containing integer values. And in the output there will be a string with all array elements concatenated with the specified characters. Inputarray:[1,5,3,6]Ou

How to convert 2D array to 1D array in PHP How to convert 2D array to 1D array in PHP Jul 07, 2023 pm 06:42 PM

How to convert a two-dimensional array to a one-dimensional array in PHP In PHP development, you often encounter scenarios where you need to convert a two-dimensional array into a one-dimensional array. This article will introduce several common methods to help you complete this task easily. Method 1: Use loop traversal The simplest and most straightforward method is to use a loop to traverse a two-dimensional array and add each element to a new one-dimensional array. Here is a code example using this method: functionflattenArray($array){$result

Detailed explanation of PHP 5.5 functions: How to use the array_column function to extract a certain column in a two-dimensional array Detailed explanation of PHP 5.5 functions: How to use the array_column function to extract a certain column in a two-dimensional array Jul 30, 2023 am 08:45 AM

Detailed explanation of PHP5.5 functions: How to use the array_column function to extract a certain column in a two-dimensional array. In the PHP5.5 version, the array_column function was introduced. It is a very practical function that can extract a specified column of data from a two-dimensional array. This comes in handy when working with large amounts of data, allowing us to quickly get the data we need. The basic syntax of the array_column function is as follows: arrayarray_column(array$

Does php have two-dimensional arrays? Does php have two-dimensional arrays? Aug 03, 2023 pm 02:45 PM

PHP has a two-dimensional array, which is a special type of array that can store other arrays as elements. The declaration and access of a two-dimensional array are very simple. You can use the "array" function to create a two-dimensional array and use indexing or association. Arrays, as their elements, are very useful in practical programming and can be used to process various complex data structures.

See all articles