PHP array introductory tutorial - array filling

WBOY
Release: 2016-07-25 08:57:53
Original
1033 people have browsed it
This article introduces an example of array filling in PHP arrays. Friends in need can refer to it.

In PHP programming, to fill array elements, you can use the array_fill() function.

Look at the following example, array_fill() function - fill array function:

<?PHP
//数组填充 
//array_fill()例子
//by bbs.it-home.org
$array = range(1,10);
$fillarray = range("a","d");
$arrayFilled = array_fill(0,5,$fillarray);//$fillarray可以是字符串,如"test".
echo "<pre class="brush:php;toolbar:false">";
print_r ($arrayFilled);
echo "
Copy after login
"; $keys = array("string","2",9,"SDK","PK"); $array2 = array_fill_keys($keys,"testing"); echo "
";
print_r ($array2);
echo "
Copy after login
"; ?>

Run result:

Array ( [0] => Array ( [0] => a [1] => b [2] => c [3] => d )

[1] => Array ( [0] => a [1] => b [2] => c [3] => d )

[2] => Array ( [0] => a [1] => b [2] => c [3] => d )

[3] => Array ( [0] => a [1] => b [2] => c [3] => d )

[4] => Array ( [0] => a [1] => b [2] => c [3] => d )

) Array ( [string] => testing [2] => testing [9] => testing [SDK] => testing [PK] => testing )



source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template